Objective-C ゲームにリワード ビデオを追加しようとしています。
それは与えます
タイプ 'UIViewController * _Nonnull' のパラメーターをタイプ 'AdIntegrator *const __strong' の左辺値で初期化することはできません
この行のエラー。
[[GADRewardBasedVideoAd sharedInstance] presentFromRootViewController:self];
Admob の公式チュートリアルを使用していますが、エラーが発生します。 https://developers.google.com/admob/ios/rewarded-video
完全なコード:
#import "AdIntegrator.h"
#import <GoogleMobileAds/GoogleMobileAds.h>
#import <UIKit/UIKit.h>
@implementation AdIntegrator
+ (id)shared{
static AdIntegrator* integrator = nil;
@synchronized(self){
if(integrator == nil){
integrator = [[self alloc] init];
}
}
return integrator;
}
#pragma mark Core Methods
- (void)initAds{
NSLog(@"[Ads] initialization");
[GADRewardBasedVideoAd sharedInstance].delegate = self;
[[GADRewardBasedVideoAd sharedInstance] loadRequest:[GADRequest request]
withAdUnitID:@"ca-app-pub-3940256099942544/1712485313"];
}
- (void)rewardBasedVideoAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd
didRewardUserWithReward:(GADAdReward *)reward {
NSString *rewardMessage =
[NSString stringWithFormat:@"Reward received with currency %@ , amount %lf",
reward.type,
[reward.amount doubleValue]];
NSLog(rewardMessage);
}
- (void)rewardBasedVideoAdDidReceiveAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
NSLog(@"Reward based video ad is received.");
}
- (void)rewardBasedVideoAdDidOpen:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
NSLog(@"Opened reward based video ad.");
}
- (void)rewardBasedVideoAdDidStartPlaying:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
NSLog(@"Reward based video ad started playing.");
}
- (void)rewardBasedVideoAdDidCompletePlaying:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
NSLog(@"Reward based video ad has completed.");
}
- (void)rewardBasedVideoAdDidClose:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
NSLog(@"Reward based video ad is closed.");
}
- (void)rewardBasedVideoAdWillLeaveApplication:(GADRewardBasedVideoAd *)rewardBasedVideoAd {
NSLog(@"Reward based video ad will leave application.");
}
- (void)rewardBasedVideoAd:(GADRewardBasedVideoAd *)rewardBasedVideoAd
didFailToLoadWithError:(NSError *)error {
NSLog(@"Reward based video ad failed to load.");
}
-(void)showBanner{
NSLog(@"[Ads] show banner");
}
-(void)hideBanner{
NSLog(@"[Ads] hide banner");
}
-(bool)isBannerVisible{
return true;
}
-(bool)isRewardedVideoAvialable{
return true;
}
-(void)showInterstitial{
NSLog(@"[Ads] show interstitial");
}
-(void)showRewardedVideo{
NSLog(@"[Ads] show rewarded video");
if ([[GADRewardBasedVideoAd sharedInstance] isReady]) {
[[GADRewardBasedVideoAd sharedInstance] presentFromRootViewController:self];//This line is problematic.
}
}
-(void)buttonActivated:(NSString*) name{
}
-(bool)buttonVisible:(NSString*)name{
return true;
}
#pragma mark Integration
@end
なぜこのエラーが発生するのですか? どうすれば解決できますか?