在我当前的应用程序中,我正在通过vungle实现激励广告。用户播放广告后,我想对其进行编码,这样,如果广告已经加载并且广告已经完成,我的应用程序会将您重定向到另一个名为Continue的SKScene。然而,我不知道如何检查广告是否已经完成/加载,以便有效地重定向用户。我想确保没有漏洞,如果没有互联网连接/广告没有加载,就无法访问激励措施。如有任何帮助,我们将不胜感激,提前表示感谢。下面是我当前的代码
在AppDelegate.m 中
NSString* appID = @"XXXXXXXX";
VungleSDK* sdk = [VungleSDK sharedSDK];
// start vungle publisher library
[sdk startWithAppId:appID];
在GameViewController.m下ViewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"showVideo" object:nil];
Under handleNotification:(NSNotification *)notification
if ([notification.name isEqualToString:@"showVideo"]) {
VungleSDK* sdk = [VungleSDK sharedSDK];
NSError *error;
[sdk playAd:self error:&error];
}
在GamePlay.m下的按钮类
[[NSNotificationCenter defaultCenter] postNotificationName:@"showVideo" object:nil];
也在GamePlay.m 中
- (void)vungleSDKwillCloseAdWithViewInfo:(NSDictionary *)viewInfo willPresentProductSheet:(BOOL)willPresentProductSheet {
//Verify that the view was completed before rewarding the user
BOOL completedView = [[viewInfo valueForKey:@"completedView"] boolValue];
if (completedView) {
Continue *Continue1 = [Continue sceneWithSize:self.frame.size];
SKTransition *transition = [SKTransition revealWithDirection:SKTransitionDirectionDown duration:0.75];
[self.view presentScene:Continue1 transition:transition];
[self.button play];
}
}
您需要实现VungleSDK Delegate,它可以在高级设置指南的Delegate Methods下找到。
回调(void)vungleSDKwillCloseAdWithViewInfo:将向您传递一个viewInfo字典。
如果键completedView返回YES,则可以继续并奖励用户的视图。