您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
 
 
 

100 行
2.5 KiB

  1. // Copyright 2014 Google Inc. All Rights Reserved.
  2. #import "GADUInterstitial.h"
  3. #import <CoreGraphics/CoreGraphics.h>
  4. #import <UIKit/UIKit.h>
  5. #import "GADUPluginUtil.h"
  6. #import "UnityAppController.h"
  7. #import "UnityInterface.h"
  8. @interface GADUInterstitial () <GADInterstitialDelegate>
  9. @end
  10. @implementation GADUInterstitial
  11. - (id)initWithInterstitialClientReference:(GADUTypeInterstitialClientRef *)interstitialClient
  12. adUnitID:(NSString *)adUnitID {
  13. self = [super init];
  14. if (self) {
  15. _interstitialClient = interstitialClient;
  16. _interstitial = [[GADInterstitial alloc] initWithAdUnitID:adUnitID];
  17. _interstitial.delegate = self;
  18. }
  19. return self;
  20. }
  21. - (void)dealloc {
  22. _interstitial.delegate = nil;
  23. }
  24. - (void)loadRequest:(GADRequest *)request {
  25. [self.interstitial loadRequest:request];
  26. }
  27. - (BOOL)isReady {
  28. return self.interstitial.isReady;
  29. }
  30. - (void)show {
  31. if (self.interstitial.isReady) {
  32. UIViewController *unityController = [GADUPluginUtil unityGLViewController];
  33. [self.interstitial presentFromRootViewController:unityController];
  34. } else {
  35. NSLog(@"GoogleMobileAdsPlugin: Interstitial is not ready to be shown.");
  36. }
  37. }
  38. - (NSString *)mediationAdapterClassName {
  39. return [self.interstitial adNetworkClassName];
  40. }
  41. #pragma mark GADInterstitialDelegate implementation
  42. - (void)interstitialDidReceiveAd:(GADInterstitial *)ad {
  43. if (self.adReceivedCallback) {
  44. self.adReceivedCallback(self.interstitialClient);
  45. }
  46. }
  47. - (void)interstitial:(GADInterstitial *)ad didFailToReceiveAdWithError:(GADRequestError *)error {
  48. if (self.adFailedCallback) {
  49. NSString *errorMsg = [NSString
  50. stringWithFormat:@"Failed to receive ad with error: %@", [error localizedFailureReason]];
  51. self.adFailedCallback(self.interstitialClient,
  52. [errorMsg cStringUsingEncoding:NSUTF8StringEncoding]);
  53. }
  54. }
  55. - (void)interstitialWillPresentScreen:(GADInterstitial *)ad {
  56. if ([GADUPluginUtil pauseOnBackground]) {
  57. UnityPause(YES);
  58. }
  59. if (self.willPresentCallback) {
  60. self.willPresentCallback(self.interstitialClient);
  61. }
  62. }
  63. - (void)interstitialWillDismissScreen:(GADInterstitial *)ad {
  64. // Callback is not forwarded to Unity.
  65. }
  66. - (void)interstitialDidDismissScreen:(GADInterstitial *)ad {
  67. if (UnityIsPaused()) {
  68. UnityPause(NO);
  69. }
  70. if (self.didDismissCallback) {
  71. self.didDismissCallback(self.interstitialClient);
  72. }
  73. }
  74. - (void)interstitialWillLeaveApplication:(GADInterstitial *)ad {
  75. if (self.willLeaveCallback) {
  76. self.willLeaveCallback(self.interstitialClient);
  77. }
  78. }
  79. @end