https://developers.google.com/admob/ios/rewarded-ads-v7?hl=ja
記事をもとにリワード広告を実装しました。
その際広告を一定時間見ると..
func rewardBasedVideoAd(_ rewardBasedVideoAd: GADRewardBasedVideoAd, didRewardUserWith reward: GADAdReward) { print(Int(truncating: reward.amount)) // ここでポイントを付与する }
としています。
1回目は問題なくポイント付与されるのですが2回目以降はリワード広告自体が表示されません。
https://i-app-tec.com/ios/rewarded-video-ads.html#4 をもとに
func rewardBasedVideoAdDidClose(_ rewardBasedVideoAd: GADRewardBasedVideoAd) { statusLabel.text = "ad is closed" setupRewardBasedVideoAd() print("Reward based video ad is closed.") }
(も書いてみたのですがそもそも 警告
が出ているので微妙です。)
GADRewardBasedVideoAd
は非推奨のようなので Fix
で修正しています。
ボタンを押して何回か(例:3回を上限とする)リワード広告を表示して
ポイントを付与
したいです。
言語は Swift
です。
広告が表示されないのはテスト広告だからでしょうか。
それともドキュメント通りの実装だと1種類の広告しか出ないのでしょうか。
## 知りたいこと ・リワード広告を呼び出すたびに違う広告を表示して試聴時間が一定時間経過するとポイントが付与される実装が知りたいです。
詳しい方いましたらアドバイスお願いいたします。
追記
ドキュメンそのままBuildするとエラーが4つ出ます。
// // RewardAdViewController.swift import UIKit import GoogleMobileAds class RewardAdViewController: UIViewController, GADRewardedAdDelegate { var rewardedAd: GADRewardedAd? override func viewDidLoad() { super.viewDidLoad() rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313") rewardedAd?.load(GADRequest()) { error in if let error = error { // Handle ad failed to load case. print("読み込み失敗") } else { // Ad successfully loaded. print("読み込み成功") } } rewardedAd = createAndLoadRewardedAd() } // MARK: - Navigation @IBAction func stratRewardAd(_ sender: Any) { if rewardedAd?.isReady == true { rewardedAd?.present(fromRootViewController: self, delegate:self) } } // MARK: - AdMob /// Tells the delegate that the user earned a reward. func rewardedAd(_ rewardedAd: GADRewardedAd, userDidEarn reward: GADAdReward) { print("Reward received with currency: (reward.type), amount (reward.amount).") } /// Tells the delegate that the rewarded ad was presented. func rewardedAdDidPresent(_ rewardedAd: GADRewardedAd) { print("Rewarded ad presented.") } /// Tells the delegate that the rewarded ad was dismissed. func rewardedAdDidDismiss(_ rewardedAd: GADRewardedAd) { print("Rewarded ad dismissed.") rewardedAd = createAndLoadRewardedAd() } /// Tells the delegate that the rewarded ad failed to present. func rewardedAd(_ rewardedAd: GADRewardedAd, didFailToPresentWithError error: Error) { print("Rewarded ad failed to present.") } func createAndLoadRewardedAd() { rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313") rewardedAd?.load(GADRequest()) { error in if let error = error { print("Loading failed: (error)") } else { print("Loading Succeeded") } } return rewardedAd } }
import UIKit import GoogleMobileAds class RewardAdViewController: UIViewController, GADRewardedAdDelegate { var rewardedAd: GADRewardedAd? override func viewDidLoad() { super.viewDidLoad() rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313") rewardedAd?.load(GADRequest()) { error in if error != nil { // Handle ad failed to load case. print("読み込み失敗") } else { // Ad successfully loaded. print("読み込み成功") } } } // MARK: - Navigation @IBAction func stratRewardAd(_ sender: Any) { if rewardedAd?.isReady == true { rewardedAd?.present(fromRootViewController: self, delegate:self) } } // MARK: - AdMob /// Tells the delegate that the user earned a reward. func rewardedAd(_ rewardedAd: GADRewardedAd, userDidEarn reward: GADAdReward) { print("Reward received with currency: (reward.type), amount (reward.amount).") } /// Tells the delegate that the rewarded ad was presented. func rewardedAdDidPresent(_ rewardedAd: GADRewardedAd) { print("Rewarded ad presented.") } /// Tells the delegate that the rewarded ad was dismissed. func rewardedAdDidDismiss(_ rewardedAd: GADRewardedAd) { print("Rewarded ad dismissed.") } /// Tells the delegate that the rewarded ad failed to present. func rewardedAd(_ rewardedAd: GADRewardedAd, didFailToPresentWithError error: Error) { print("Rewarded ad failed to present.") } func createAndLoadRewardedAd() { rewardedAd = GADRewardedAd(adUnitID: "ca-app-pub-3940256099942544/1712485313") rewardedAd?.load(GADRequest()) { error in if let error = error { print("Loading failed: (error)") } else { print("Loading Succeeded") } } // return rewardedAd } }
// デバッグエリアログ 読み込み成功 Rewarded ad presented. Reward received with currency: coins, amount 10. 2021-02-28 14:59:02.513241+0900 iOS-Reward-Ad-Project[8303:164050] [View] First responder error: non-key window attempting reload - allowing due to manual keyboard (first responder window is <UIWindow: 0x7ffa14e12a80; frame = (0 0; 414 896); hidden = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x6000039291a0>; layer = <UIWindowLayer: 0x6000037f40e0>>, key window is <UIWindow: 0x7ffa14d09b80; frame = (0 0; 414 896); gestureRecognizers = <NSArray: 0x6000039f4d80>; layer = <UIWindowLayer: 0x60000379c080>>) Rewarded ad dismissed. 2021-02-28 14:59:02.798589+0900 iOS-Reward-Ad-Project[8303:164050] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}> 2021-02-28 14:59:02.798776+0900 iOS-Reward-Ad-Project[8303:164050] [ProcessSuspension] 0x109dfe8c0 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 8311, error: Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing} 2021-02-28 14:59:02.920755+0900 iOS-Reward-Ad-Project[8303:164050] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Suspended" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}> 2021-02-28 14:59:02.922318+0900 iOS-Reward-Ad-Project[8303:164050] [ProcessSuspension] 0x109dfe900 - ProcessAssertion: Failed to acquire RBS Suspended assertion 'WebProcess Suspended Assertion' for process with PID 8311, error: Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Suspended" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing} 2021-02-28 14:59:02.999928+0900 iOS-Reward-Ad-Project[8303:164981] AudioObjectRemovePropertyListener: no object with given ID 0 2021-02-28 14:59:03.000632+0900 iOS-Reward-Ad-Project[8303:164981] AudioObjectRemovePropertyListener: no object with given ID 0 2021-02-28 14:59:03.001292+0900 iOS-Reward-Ad-Project[8303:164981] AudioObjectRemovePropertyListener: no object with given ID 0 2021-02-28 14:59:32.712346+0900 iOS-Reward-Ad-Project[8303:164050] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/02/27 16:45 編集
2021/02/28 00:38
2021/02/28 05:48
2021/02/28 05:54
2021/02/28 06:00
2021/02/28 07:19
2021/02/28 08:58 編集
2021/02/28 08:57
2021/02/28 08:58
2021/02/28 08:59
2021/02/28 08:59
2021/02/28 09:00
2021/02/28 09:08
2021/02/28 09:09
2021/02/28 09:13
2021/02/28 09:22
2021/02/28 09:25
2021/02/28 09:27
2021/02/28 09:33
2021/02/28 09:34
2021/02/28 09:36
2021/02/28 09:41
2021/02/28 09:43
2021/02/28 09:46
2021/02/28 09:48