diff --git a/HD wallpaper.xcworkspace/xcuserdata/aaa.xcuserdatad/UserInterfaceState.xcuserstate b/HD wallpaper.xcworkspace/xcuserdata/aaa.xcuserdatad/UserInterfaceState.xcuserstate index bae5802..b1b2be6 100644 Binary files a/HD wallpaper.xcworkspace/xcuserdata/aaa.xcuserdatad/UserInterfaceState.xcuserstate and b/HD wallpaper.xcworkspace/xcuserdata/aaa.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/HD wallpaper/AppDelegate.m b/HD wallpaper/AppDelegate.m index 356efdf..a6d6121 100644 --- a/HD wallpaper/AppDelegate.m +++ b/HD wallpaper/AppDelegate.m @@ -17,10 +17,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[WallPapaerADManager shareInstance] configureAD]; - [[WallPapaerADManager shareInstance] initOpenAD]; + self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.window.backgroundColor = [UIColor whiteColor]; + [self.window makeKeyAndVisible]; WPOnePageViewController *wpHome = [[WPOnePageViewController alloc] init]; wpHome.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"tab1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"tab11"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; @@ -47,7 +48,7 @@ tb.viewControllers = @[wpHomeNV,wpHotNV,wpEditNV,wpMyNV]; tb.selectedIndex = 0; self.window.rootViewController = tb; - [self.window makeKeyAndVisible]; + return YES; } diff --git a/HD wallpaper/WPAllWallpaperViewController.m b/HD wallpaper/WPAllWallpaperViewController.m index 869fda8..a955a02 100644 --- a/HD wallpaper/WPAllWallpaperViewController.m +++ b/HD wallpaper/WPAllWallpaperViewController.m @@ -4,7 +4,7 @@ #import "WPAllWallpaperViewController.h" #import "WPDetailViewController.h" - +#import "WallPapaerADManager.h" #define WPScreen_w [UIScreen mainScreen].bounds.size.width #define WPScreen_h [UIScreen mainScreen].bounds.size.height #define WP_COLOR_WITH_HEX(HEX) [UIColor colorWithRed:((HEX >> 16) & 0xFF) / 255.0f green:((HEX >> 8) & 0xFF) / 255.0f blue:((HEX) & 0xFF) / 255.0f alpha:1.0f] @@ -17,7 +17,11 @@ @implementation WPAllWallpaperViewController - (void)backItemEvent{ - [self.navigationController popViewControllerAnimated:YES]; + __weak typeof(self) weakSelf = self; + [[WallPapaerADManager shareInstance] showIntersitialAD_Back:^(NSInteger actionType) { + [weakSelf.navigationController popViewControllerAnimated:YES]; + }]; +// [self.navigationController popViewControllerAnimated:YES]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; diff --git a/HD wallpaper/WPDetailViewController.m b/HD wallpaper/WPDetailViewController.m index 45d43f3..77528bd 100644 --- a/HD wallpaper/WPDetailViewController.m +++ b/HD wallpaper/WPDetailViewController.m @@ -3,7 +3,7 @@ #import "WPDetailViewController.h" #import "AppDelegate.h" - +#import "WallPapaerADManager.h" #define WPScreen_w [UIScreen mainScreen].bounds.size.width #define WPScreen_h [UIScreen mainScreen].bounds.size.height #define WP_COLOR_WITH_HEX(HEX) [UIColor colorWithRed:((HEX >> 16) & 0xFF) / 255.0f green:((HEX >> 8) & 0xFF) / 255.0f blue:((HEX) & 0xFF) / 255.0f alpha:1.0f] @@ -17,7 +17,11 @@ @implementation WPDetailViewController - (void)backItemEvent{ - [self.navigationController popViewControllerAnimated:YES]; + __weak typeof(self) weakSelf = self; + [[WallPapaerADManager shareInstance] showIntersitialAD_Back:^(NSInteger actionType) { + [weakSelf.navigationController popViewControllerAnimated:YES]; + }]; +// [self.navigationController popViewControllerAnimated:YES]; } - (void)saveItemEvent{ UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:self.data[self.index]], self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil); diff --git a/HD wallpaper/WPSearchViewController.m b/HD wallpaper/WPSearchViewController.m index 2ee7ed8..0424be8 100644 --- a/HD wallpaper/WPSearchViewController.m +++ b/HD wallpaper/WPSearchViewController.m @@ -2,6 +2,7 @@ // WPSearchViewController.m #import "WPSearchViewController.h" +#import "WallPapaerADManager.h" #define WPScreen_w [UIScreen mainScreen].bounds.size.width #define WPScreen_h [UIScreen mainScreen].bounds.size.height #define WP_COLOR_WITH_HEX(HEX) [UIColor colorWithRed:((HEX >> 16) & 0xFF) / 255.0f green:((HEX >> 8) & 0xFF) / 255.0f blue:((HEX) & 0xFF) / 255.0f alpha:1.0f] @@ -12,7 +13,11 @@ @implementation WPSearchViewController - (void)backItemEvent{ - [self.navigationController popViewControllerAnimated:YES]; + __weak typeof(self) weakSelf = self; + [[WallPapaerADManager shareInstance] showIntersitialAD_Back:^(NSInteger actionType) { + [weakSelf.navigationController popViewControllerAnimated:YES]; + }]; + } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; diff --git a/HD wallpaper/WPwallpaperViewController.m b/HD wallpaper/WPwallpaperViewController.m index 90504b3..81b8316 100644 --- a/HD wallpaper/WPwallpaperViewController.m +++ b/HD wallpaper/WPwallpaperViewController.m @@ -4,6 +4,7 @@ #import "WPwallpaperViewController.h" #import "WPDetailViewController.h" #import "AppDelegate.h" +#import "WallPapaerADManager.h" #define WPScreen_w [UIScreen mainScreen].bounds.size.width #define WPScreen_h [UIScreen mainScreen].bounds.size.height #define WP_COLOR_WITH_HEX(HEX) [UIColor colorWithRed:((HEX >> 16) & 0xFF) / 255.0f green:((HEX >> 8) & 0xFF) / 255.0f blue:((HEX) & 0xFF) / 255.0f alpha:1.0f] @@ -18,7 +19,12 @@ @implementation WPwallpaperViewController - (void)backItemEvent{ - [self.navigationController popViewControllerAnimated:YES]; + __weak typeof(self) weakSelf = self; + [[WallPapaerADManager shareInstance] showIntersitialAD_Back:^(NSInteger actionType) { + [weakSelf.navigationController popViewControllerAnimated:YES]; + }]; + +// [self.navigationController popViewControllerAnimated:YES]; } - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; diff --git a/HD wallpaper/WallPapaerADManager/WallPapaerADManager.h b/HD wallpaper/WallPapaerADManager/WallPapaerADManager.h index 9b9e99c..c66917c 100644 --- a/HD wallpaper/WallPapaerADManager/WallPapaerADManager.h +++ b/HD wallpaper/WallPapaerADManager/WallPapaerADManager.h @@ -8,7 +8,7 @@ #import NS_ASSUME_NONNULL_BEGIN - +typedef void(^WallPapaerADManagerCallback)(NSInteger actionType);//actionType,1表示关闭广告 @interface WallPapaerADManager : NSObject + (instancetype)shareInstance; @@ -17,6 +17,13 @@ NS_ASSUME_NONNULL_BEGIN - (void)initOpenAD; - (void)showOpenAD; + +- (void)initIntersitialAD; +- (void)showIntersitialAD_Search:(WallPapaerADManagerCallback)callback; +- (void)showIntersitialAD_Save:(WallPapaerADManagerCallback)callback ; +- (void)showIntersitialAD_Back:(WallPapaerADManagerCallback)callback ; + +@property (nonatomic,copy) WallPapaerADManagerCallback callback; @end NS_ASSUME_NONNULL_END diff --git a/HD wallpaper/WallPapaerADManager/WallPapaerADManager.m b/HD wallpaper/WallPapaerADManager/WallPapaerADManager.m index a69a6ce..c671030 100644 --- a/HD wallpaper/WallPapaerADManager/WallPapaerADManager.m +++ b/HD wallpaper/WallPapaerADManager/WallPapaerADManager.m @@ -7,6 +7,7 @@ #import "WallPapaerADManager.h" #import + @interface WallPapaerADManager() @property (nonatomic,strong) MAAppOpenAd *openAD; @property (nonatomic,strong) MAInterstitialAd *interstitialAD_Back; @@ -41,6 +42,12 @@ // Initialize the SDK with the configuration [[ALSdk shared] initializeWithConfiguration: _adConfig completionHandler:^(ALSdkConfiguration *sdkConfig) { // Start loading ads + NSLog(@"zzh ....sdkconfig:\n%@",sdkConfig); + + [[WallPapaerADManager shareInstance] initOpenAD]; + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [[WallPapaerADManager shareInstance] initIntersitialAD]; + }); }]; } @@ -61,13 +68,57 @@ return self; } + - (void)initOpenAD{ - __weak typeof(self)wealSelf = self; - [[ALSdk shared] initializeWithConfiguration:_adConfig completionHandler:^(ALSdkConfiguration * _Nonnull configuration) { - wealSelf.openAD = [[MAAppOpenAd alloc] initWithAdUnitIdentifier:kWallPaper_OpenAD]; - wealSelf.openAD.delegate = wealSelf; - [wealSelf.openAD loadAd]; - }]; + self.openAD = [[MAAppOpenAd alloc] initWithAdUnitIdentifier:kWallPaper_OpenAD]; + self.openAD.delegate = self; + [self.openAD loadAd]; +} + +//初始化插页广告 +- (void)initIntersitialAD { + self.interstitialAD_Back = [[MAInterstitialAd alloc] initWithAdUnitIdentifier: kInterstitial_BackAD]; + self.interstitialAD_Back.delegate = self; + [self.interstitialAD_Back loadAd]; + + self.interstitialAD_Save = [[MAInterstitialAd alloc] initWithAdUnitIdentifier: kInterstitial_SaveAD]; + self.interstitialAD_Save.delegate = self; + [self.interstitialAD_Save loadAd]; + + self.interstitialAD_Search = [[MAInterstitialAd alloc] initWithAdUnitIdentifier: kInterstitial_SearchAD]; + self.interstitialAD_Search.delegate = self; + [self.interstitialAD_Search loadAd]; +} + +- (void)showIntersitialAD_Back:(WallPapaerADManagerCallback)callback { + self.callback = callback; + if ( [self.interstitialAD_Back isReady] ){ + [self.interstitialAD_Back showAd]; + } + else { + self.callback(1); + } +} + + +- (void)showIntersitialAD_Save:(WallPapaerADManagerCallback)callback { + self.callback = callback; + if ( [self.interstitialAD_Save isReady] ){ + [self.interstitialAD_Save showAd]; + } + else { + self.callback(1); + } +} + +- (void)showIntersitialAD_Search:(WallPapaerADManagerCallback)callback { + self.callback = callback; + if ( [self.interstitialAD_Search isReady] ){ + [self.interstitialAD_Search showAd]; + } + else { + self.callback(1); + } } - (void)showOpenAD { @@ -76,9 +127,9 @@ return; } - if ( [self.openAD isReady] ) - { - [self.openAD showAdForPlacement: @"«test-placement-ID»"]; + if ( [self.openAD isReady] ){ +// [self.openAD showAdForPlacement: @"«test-placement-ID»"]; + [self.openAD showAd]; } else { @@ -111,7 +162,7 @@ } - (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(MAError *)error { - NSLog(@"加载广告失败...."); + NSLog(@"加载广告失败.... :%@ err:%@",adUnitIdentifier,error); if([adUnitIdentifier isEqualToString:self.openAD.adUnitIdentifier]) { self.retryAttempt_OpenAD++; @@ -157,6 +208,9 @@ - (void)didHideAd:(MAAd *)ad{ NSLog(@"隐藏了ad...."); + if (self.callback) { + self.callback(1); + } [self loadAD:ad]; }