AdMobのリワード動画を実装しようとしています。
googleが提供しているサンプルをこちらからダウンロードし、pod install
、pod update
をした上でシミュレーター上で実行すると問題無く動画が再生されます。
サンプルURL:https://github.com/googleads/googleads-mobile-ios-examples
ファイル: googleads-mobile-ios-examples-master/Swift/admob/RewardedVideoExample/RewardedVideoExample.xcworkspace
ですが、実機で実行するとエラーのアラートとログが出力され、動画が再生できません。
実機ログ(2017/07/20 19:40編集 文字超過のため削除)
Build Settings>Linking>Other Linker Flagsに-ObjCがあるか確認しましたが、最初から入力済でした。
info.plistのATSでHTTP通信を許可してみても変化なしです。
追加
Firebaseのバージョンを3.8.0などに落としてみたりしましたがだめでした。
ログの内容で色々とググってみましたが解決に至らず、解決方法をご存知でしたらご教示ください。
#2017/07/20 19:40追記
https://i-app-tec.com/ios/rewarded-video-ads.html
こちらの内容で再度試してみました。
サンプルコードのプロジェクトに新しくViewControllerを追加しています。
が、やはりシミュレーターでは再生OKで実機ではダメでした。
swift
1import Firebase 2import UIKit 3 4@UIApplicationMain 5class AppDelegate: UIResponder, UIApplicationDelegate { 6 7 var window: UIWindow? 8 9 func application(_ application: UIApplication, 10 didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 11 // Use Firebase library to configure APIs 12 FirebaseApp.configure() 13 // Initialize Google Mobile Ads SDK 14 GADMobileAds.configure(withApplicationID: "ca-app-pub-3940256099942544~1458002511") 15 16 return true 17 } 18 19}
swift
1import UIKit 2import GoogleMobileAds 3 4class AdmobViewController: UIViewController, GADRewardBasedVideoAdDelegate { 5 6 // let AdMobID = "[Your AdMob ID]" 7 let TEST_ID = "ca-app-pub-3940256099942544/1712485313" 8 var AdUnitID:String? = nil 9 10 // let simulation = true 11 12 /// Is an ad being loaded. 13 var adRequestInProgress = false 14 var adRedy = false 15 16 /// The reward-based video ad. 17 var rewardBasedVideo: GADRewardBasedVideoAd? 18 19 // Button to show AdMob 20 @IBOutlet weak var playAd: UIButton! 21 22 @IBOutlet weak var statusLabel: UILabel! 23 24 25 override func viewDidLoad() { 26 super.viewDidLoad() 27 28 // if simulation { 29 AdUnitID = TEST_ID 30 // } 31 // else{ 32 // AdUnitID = AdMobID 33 // } 34 35 rewardBasedVideo = GADRewardBasedVideoAd.sharedInstance() 36 rewardBasedVideo?.delegate = self 37 38 setupRewardBasedVideoAd() 39 40 } 41 42 func setupRewardBasedVideoAd(){ 43 statusLabel.text = "set up" 44 45 if !adRequestInProgress && rewardBasedVideo?.isReady == false { 46 rewardBasedVideo?.load(GADRequest(), 47 withAdUnitID: AdUnitID! ) 48 49 adRequestInProgress = true 50 } 51 else{ 52 print("Error: setup RewardBasedVideoAd") 53 } 54 } 55 56 @IBAction func playAd(_ sender: AnyObject) { 57 print("adRedy=\(adRedy)") 58 59 if GADRewardBasedVideoAd.sharedInstance().isReady && adRedy{ 60 GADRewardBasedVideoAd.sharedInstance().present(fromRootViewController: self) 61 adRedy = false 62 } 63 else{ 64 print("Error: Reward based video not ready") 65 } 66 } 67 68 // MARK: GADRewardBasedVideoAdDelegate implementation 69 func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, 70 didFailToLoadWithError error: Error) { 71 adRequestInProgress = false 72 statusLabel.text = "failed to load" 73 74 print("Reward based video ad failed to load: \(error.localizedDescription)") 75 } 76 77 func rewardBasedVideoAdDidReceive(_ rewardBasedVideoAd: GADRewardBasedVideoAd) { 78 statusLabel.text = "ad is received" 79 adRequestInProgress = false 80 adRedy = true 81 82 print("Reward based video ad is received.") 83 } 84 85 func rewardBasedVideoAdDidOpen(_ rewardBasedVideoAd: GADRewardBasedVideoAd) { 86 statusLabel.text = "Opened reward based video ad." 87 88 print("Opened reward based video ad.") 89 } 90 91 func rewardBasedVideoAdDidStartPlaying(_ rewardBasedVideoAd: GADRewardBasedVideoAd) { 92 print("started playing.") 93 } 94 95 func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd) { 96 statusLabel.text = "ad is closed" 97 setupRewardBasedVideoAd() 98 99 print("Reward based video ad is closed.") 100 } 101 102 func rewardBasedVideoAdWillLeaveApplication(_ rewardBasedVideoAd: GADRewardBasedVideoAd) { 103 104 print("Reward based video ad will leave application.") 105 } 106 107 func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, 108 didRewardUserWith reward: GADAdReward) { 109 print("Reward received with currency: \(reward.type), amount \(reward.amount).") 110 } 111 112 113 114 override func didReceiveMemoryWarning() { 115 super.didReceiveMemoryWarning() 116 // Dispose of any resources that can be recreated. 117 } 118 119 120} 121
実機ログ
2017-07-20 19:21:10.786265+0900 RewardedVideoExample[17506:1685024] [Firebase/Analytics][I-ACS023007] Firebase Analytics v.40002000 started 2017-07-20 19:21:10.787 RewardedVideoExample[17506] <Notice> [Firebase/Analytics][I-ACS023007] Firebase Analytics v.40002000 started 2017-07-20 19:21:10.789715+0900 RewardedVideoExample[17506:1685024] [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r) 2017-07-20 19:21:10.791 RewardedVideoExample[17506] <Notice> [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r) 2017-07-20 19:21:11.714092+0900 RewardedVideoExample[17506:1684957] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 2017-07-20 19:21:11.716054+0900 RewardedVideoExample[17506:1684957] [MC] Reading from public effective user settings. 2017-07-20 19:21:12.132385+0900 RewardedVideoExample[17506:1685033] TIC Read Status [1:0x0]: 1:57 2017-07-20 19:21:12.132457+0900 RewardedVideoExample[17506:1685033] TIC Read Status [1:0x0]: 1:57 2017-07-20 19:21:12.364643+0900 RewardedVideoExample[17506:1685066] [Firebase/Analytics][I-ACS003007] Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist 2017-07-20 19:21:12.366 RewardedVideoExample[17506] <Notice> [Firebase/Analytics][I-ACS003007] Successfully created Firebase Analytics App Delegate Proxy automatically. To disable the proxy, set the flag FirebaseAppDelegateProxyEnabled to NO in the Info.plist 2017-07-20 19:21:12.420720+0900 RewardedVideoExample[17506:1685066] [Firebase/Analytics][I-ACS032003] iAd framework is not linked. Search Ad Attribution Reporter is disabled. 2017-07-20 19:21:12.421 RewardedVideoExample[17506] <Warning> [Firebase/Analytics][I-ACS032003] iAd framework is not linked. Search Ad Attribution Reporter is disabled. 2017-07-20 19:21:12.422509+0900 RewardedVideoExample[17506:1685066] [Firebase/Analytics][I-ACS023012] Firebase Analytics enabled 2017-07-20 19:21:12.422 RewardedVideoExample[17506] <Notice> [Firebase/Analytics][I-ACS023012] Firebase Analytics enabled 2017-07-20 19:21:12.507906+0900 RewardedVideoExample[17506:1685028] <Google> Cannot find an ad network adapter with the name(s): com.google.DummyAdapter. Remember to link all required ad network adapters and SDKs, and set -ObjC in the 'Other Linker Flags' setting of your build target. Reward based video ad failed to load: No ad returned from any ad server. 2017-07-20 19:21:27.199211+0900 RewardedVideoExample[17506:1685066] TIC Read Status [5:0x0]: 1:57 2017-07-20 19:21:27.199416+0900 RewardedVideoExample[17506:1685066] TIC Read Status [5:0x0]: 1:57 2017-07-20 19:21:27.202074+0900 RewardedVideoExample[17506:1685066] [Firebase/Analytics][I-ACS023130] Configuration not found. Using default configuration 2017-07-20 19:21:27.202 RewardedVideoExample[17506] <Warning> [Firebase/Analytics][I-ACS023130] Configuration not found. Using default configuration 2017-07-20 19:21:27.420460+0900 RewardedVideoExample[17506:1685157] TIC Read Status [6:0x0]: 1:57 2017-07-20 19:21:27.420599+0900 RewardedVideoExample[17506:1685157] TIC Read Status [6:0x0]: 1:57 adRedy=false Error: Reward based video not ready
swift
1func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, 2 didFailToLoadWithError error: Error) { 3 adRequestInProgress = false 4 statusLabel.text = "failed to load" 5 6 print("Reward based video ad failed to load: \(error.localizedDescription)") 7 }
からは
Reward based video ad failed to load: No ad returned from any ad server.
と返ってきます。
なお、自分で作成したプロジェクト上で、ApplicationIDとGoogleService-Info.plistをFirebaseより生成したもので実行しても結果は同じです。
シミュレーターではできるのに実機で出来ない理由がわかりません。。。
回答1件
あなたの回答
tips
プレビュー