I’m at present making an attempt to create a cellular software with rewarded adverts and I battle with the code on XCode.
For now I’ve already built-in interstitial adverts and I want to adapt the code for rewarded adverts.
Right here is my present working code for interstitial adverts tailored from one thing discovered on Github:
UIView *gView;
UIViewController *gViewColtroller;
@interface adInterstitial : NSObject
/// The interstitial advert.
@property(nonatomic, sturdy) GADInterstitial *interstitial;
@property (sturdy, nonatomic) GADRequest *request;
@finish
@implementation adInterstitial
-(id)init {
[self createAndLoadInterstitial];
NSLog(@"adInterstitial init");
return self;
}
- (void)createAndLoadInterstitial {
self.interstitial = [[GADInterstitial alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910"]; // check id
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = window.rootViewController;
self.interstitial.delegate = self;
GADRequest *request = [GADRequest request];
request.testDevices = @[ kGADSimulatorID, @"2077ef9a63d2b398840261c8221a0c9a" ];
[self.interstitial loadRequest:request];
NSLog(@"createAndLoadInterstitial");
}
- (void)interstitialWillDismissScreen:(GADInterstitial *)advert {
// Methodology for reloading the thing as a way to present adverts once more
NSLog(@"interstitialWillDismissScreen");
[self createAndLoadInterstitial];
}
- (void)InterstitialView { // present interstitial ADS
if (self.interstitial.isReady) {
NSLog(@"Present interstitial ADS!");
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = window.rootViewController;
[self.interstitial presentFromRootViewController:rootViewController];
} else {
NSLog(@"interstitial Advert wasn't prepared");
}
}
@finish
And right here is my try with rewarded adverts:
@interface adRewarded : NSObject
/// The interstitial advert.
@property(nonatomic, sturdy) GADRewardedAd *rewarded;
@property (sturdy, nonatomic) GADRequest *request;
@finish
@implementation adRewarded
-(id)init {
[self createAndLoadRewarded];
NSLog(@"adRewarded init");
return self;
}
- (void)createAndLoadRewarded {
self.rewarded = [[GADRewardedAd alloc] initWithAdUnitID:@"ca-app-pub-3940256099942544/4411468910"]; // check id
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = window.rootViewController;
self.rewarded.delegate = self;
GADRequest *request = [GADRequest request];
request.testDevices = @[ kGADSimulatorID, @"2077ef9a63d2b398840261c8221a0c9a" ];
[self.rewarded loadRequest:request];
NSLog(@"createAndLoadRewarded");
}
- (void)interstitialWillDismissScreen:(GADRewardedAd *)advert {
// Methodology for reloading the thing as a way to present adverts once more
NSLog(@"rewardedWillDismissScreen");
[self createAndLoadRewarded];
}
- (void)RewardedView { // present interstitial ADS
if (self.rewarded.isReady) {
NSLog(@"Present rewarded ADS!");
UIWindow *window = [UIApplication sharedApplication].keyWindow;
UIViewController *rootViewController = window.rootViewController;
[self.rewarded presentFromRootViewController:rootViewController];
} else {
NSLog(@"rewarded Advert wasn't prepared");
}
}
@finish
And I get hold of an error on the road : self.rewarded.delegate = self;
The error is : Property 'delegate' not discovered on object of sort 'GADRewardedAd'
Only for data to begin the advert in Python I’m utilizing the next code:
from pyobjus import autoclass
current_ad = autoclass("adInterstitial").alloc().init()
current_ad.present()
I additionally tried to make use of the Google documentation https://builders.google.com/admob/ios/rewarded#objective-c to create a brand new model however I battle with the thing named ViewController.
Both I get this error if I simply copy paste the instance:
Can not discover interface declaration for ViewController; did you imply UIViewController
or I get this error if I exchange with UIViewController:
Can not synthesize weak property in file utilizing handbook reference counting
Would you please know resolve it ?
Thanks upfront!