This commit is contained in:
bluesea 2024-07-03 18:14:32 +08:00
parent a74fd9c353
commit 24b476678a
8 changed files with 100 additions and 19 deletions

View File

@ -17,10 +17,11 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[WallPapaerADManager shareInstance] configureAD]; [[WallPapaerADManager shareInstance] configureAD];
[[WallPapaerADManager shareInstance] initOpenAD];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor]; self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
WPOnePageViewController *wpHome = [[WPOnePageViewController alloc] init]; WPOnePageViewController *wpHome = [[WPOnePageViewController alloc] init];
wpHome.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"" image:[[UIImage imageNamed:@"tab1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"tab11"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 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.viewControllers = @[wpHomeNV,wpHotNV,wpEditNV,wpMyNV];
tb.selectedIndex = 0; tb.selectedIndex = 0;
self.window.rootViewController = tb; self.window.rootViewController = tb;
[self.window makeKeyAndVisible];
return YES; return YES;
} }

View File

@ -4,7 +4,7 @@
#import "WPAllWallpaperViewController.h" #import "WPAllWallpaperViewController.h"
#import "WPDetailViewController.h" #import "WPDetailViewController.h"
#import "WallPapaerADManager.h"
#define WPScreen_w [UIScreen mainScreen].bounds.size.width #define WPScreen_w [UIScreen mainScreen].bounds.size.width
#define WPScreen_h [UIScreen mainScreen].bounds.size.height #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] #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 @implementation WPAllWallpaperViewController
- (void)backItemEvent{ - (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{ - (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated]; [super viewWillAppear:animated];

View File

@ -3,7 +3,7 @@
#import "WPDetailViewController.h" #import "WPDetailViewController.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "WallPapaerADManager.h"
#define WPScreen_w [UIScreen mainScreen].bounds.size.width #define WPScreen_w [UIScreen mainScreen].bounds.size.width
#define WPScreen_h [UIScreen mainScreen].bounds.size.height #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] #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 @implementation WPDetailViewController
- (void)backItemEvent{ - (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{ - (void)saveItemEvent{
UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:self.data[self.index]], self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil); UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:self.data[self.index]], self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);

View File

@ -2,6 +2,7 @@
// WPSearchViewController.m // WPSearchViewController.m
#import "WPSearchViewController.h" #import "WPSearchViewController.h"
#import "WallPapaerADManager.h"
#define WPScreen_w [UIScreen mainScreen].bounds.size.width #define WPScreen_w [UIScreen mainScreen].bounds.size.width
#define WPScreen_h [UIScreen mainScreen].bounds.size.height #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] #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 @implementation WPSearchViewController
- (void)backItemEvent{ - (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{ - (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated]; [super viewWillAppear:animated];

View File

@ -4,6 +4,7 @@
#import "WPwallpaperViewController.h" #import "WPwallpaperViewController.h"
#import "WPDetailViewController.h" #import "WPDetailViewController.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "WallPapaerADManager.h"
#define WPScreen_w [UIScreen mainScreen].bounds.size.width #define WPScreen_w [UIScreen mainScreen].bounds.size.width
#define WPScreen_h [UIScreen mainScreen].bounds.size.height #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] #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 @implementation WPwallpaperViewController
- (void)backItemEvent{ - (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{ - (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated]; [super viewWillAppear:animated];

View File

@ -8,7 +8,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef void(^WallPapaerADManagerCallback)(NSInteger actionType);//actionType,1表示关闭广告
@interface WallPapaerADManager : NSObject @interface WallPapaerADManager : NSObject
+ (instancetype)shareInstance; + (instancetype)shareInstance;
@ -17,6 +17,13 @@ NS_ASSUME_NONNULL_BEGIN
- (void)initOpenAD; - (void)initOpenAD;
- (void)showOpenAD; - (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 @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -7,6 +7,7 @@
#import "WallPapaerADManager.h" #import "WallPapaerADManager.h"
#import <AppLovinSDK/AppLovinSDK.h> #import <AppLovinSDK/AppLovinSDK.h>
@interface WallPapaerADManager()<MAAdDelegate> @interface WallPapaerADManager()<MAAdDelegate>
@property (nonatomic,strong) MAAppOpenAd *openAD; @property (nonatomic,strong) MAAppOpenAd *openAD;
@property (nonatomic,strong) MAInterstitialAd *interstitialAD_Back; @property (nonatomic,strong) MAInterstitialAd *interstitialAD_Back;
@ -41,6 +42,12 @@
// Initialize the SDK with the configuration // Initialize the SDK with the configuration
[[ALSdk shared] initializeWithConfiguration: _adConfig completionHandler:^(ALSdkConfiguration *sdkConfig) { [[ALSdk shared] initializeWithConfiguration: _adConfig completionHandler:^(ALSdkConfiguration *sdkConfig) {
// Start loading ads // 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; return self;
} }
- (void)initOpenAD{ - (void)initOpenAD{
__weak typeof(self)wealSelf = self; self.openAD = [[MAAppOpenAd alloc] initWithAdUnitIdentifier:kWallPaper_OpenAD];
[[ALSdk shared] initializeWithConfiguration:_adConfig completionHandler:^(ALSdkConfiguration * _Nonnull configuration) { self.openAD.delegate = self;
wealSelf.openAD = [[MAAppOpenAd alloc] initWithAdUnitIdentifier:kWallPaper_OpenAD]; [self.openAD loadAd];
wealSelf.openAD.delegate = wealSelf; }
[wealSelf.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 { - (void)showOpenAD {
@ -76,9 +127,9 @@
return; return;
} }
if ( [self.openAD isReady] ) if ( [self.openAD isReady] ){
{ // [self.openAD showAdForPlacement: @"«test-placement-ID»"];
[self.openAD showAdForPlacement: @"«test-placement-ID»"]; [self.openAD showAd];
} }
else else
{ {
@ -111,7 +162,7 @@
} }
- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(MAError *)error { - (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(MAError *)error {
NSLog(@"加载广告失败...."); NSLog(@"加载广告失败.... :%@ err:%@",adUnitIdentifier,error);
if([adUnitIdentifier isEqualToString:self.openAD.adUnitIdentifier]) { if([adUnitIdentifier isEqualToString:self.openAD.adUnitIdentifier]) {
self.retryAttempt_OpenAD++; self.retryAttempt_OpenAD++;
@ -157,6 +208,9 @@
- (void)didHideAd:(MAAd *)ad{ - (void)didHideAd:(MAAd *)ad{
NSLog(@"隐藏了ad...."); NSLog(@"隐藏了ad....");
if (self.callback) {
self.callback(1);
}
[self loadAD:ad]; [self loadAD:ad];
} }