123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- //
- // SPSBOpenADManager.m
- // 我的社保
- //
- // Created by shanp on 2021/4/26.
- //
- #import "SPSBOpenADManager.h"
- #import <NSObject+JXHNotification.h>
- #import "AppDelegate+SPSBRootViewController.h"
- #import <JXHSystemShortcut.h>
- #import <AdSupport/AdSupport.h>
- #import <BUAdSDK/BUAdSDK.h>
- #import "SPSBUIGeneralHeader.h"
- @interface SPSBOpenADManager ()<BUSplashAdDelegate> {
- UIButton *_adSkipButton;
- BUSplashAd *_ad;
- UIView *_adBottomView;
- }
- @end
- @implementation SPSBOpenADManager
- + (instancetype)alloc {
- NSAssert(![self isMemberOfClass:[SPSBOpenADManager class]], @"SPSBOpenADManager is singleton, you should not instantiate it directly.");
- return [super alloc];
- }
- + (SPSBOpenADManager *)shareManager {
- static SPSBOpenADManager *manager = nil;
- static dispatch_once_t once;
- dispatch_once(&once, ^{
- manager = [[super allocWithZone:nil] init];
- });
-
- return manager;
- }
- + (instancetype)allocWithZone:(struct _NSZone *)zone {
- return [self shareManager];
- }
- - (void)dealloc {
- [self removeNotificationName:UIApplicationWillEnterForegroundNotification];
- }
- - (void)showAD {
- [self setOpenAD];
- [self addNotificationName:UIApplicationWillEnterForegroundNotification block:^(id object, NSDictionary *userInfo) {
- [jxh_appDelegate() showHomePage];
- }];
- }
- - (void)setOpenAD {
- // _ad = [[BUSplashView alloc] initWithSlotID:@"887888474" frame:CGRectMake(0, 0, jxh_screenWidth(), jxh_screenHeight() - SPSBStarPageBottomViewHeight - jxh_safeInsets(spsb_keyWindow()).bottom)];
- _ad = [[BUSplashAd alloc] initWithSlotID:@"887888474" adSize:(CGSize){jxh_screenWidth(), jxh_screenHeight() - SPSBStarPageBottomViewHeight - jxh_safeInsets(spsb_keyWindow()).bottom}];
- _ad.splashView.backgroundColor = spsb_FFFFFF_color(1.f);
- _ad.hideSkipButton = true;
- _ad.delegate = self;
- _ad.tolerateTimeout = 3;
- [_ad loadAdData];
- }
- - (void)splashAdDidLoad:(BUSplashAd *)splashAd {
- [_ad showSplashViewInRootViewController:spsb_homeVC()];
-
- _adSkipButton = [UIButton convenienceWithFont:spsb_font(14) target:self action:@selector(skipAd)];
- [_adSkipButton setTitle:@"跳过" titleColor:spsb_FFFFFF_color(1.f) state:JXHButtonControlStateNormal];
- _adSkipButton.backgroundColor = spsb_000000_color(0.5);
- [_adSkipButton setLayerCornerRadius:15 clipToBounds:false];
- [_ad.splashView addSubview:_adSkipButton];
- [_adSkipButton makeConstraints:^(JXHConstraintMaker *make) {
- make.trailing.equalTo(-16);
- make.top.equalTo(50);
- make.size.equalTo(CGSizeMake(50, 30));
-
- }];
-
- _adBottomView = [[UIView alloc] initWithFrame:CGRectMake(0, jxh_screenHeight() - SPSBStarPageBottomViewHeight - jxh_safeInsets(spsb_keyWindow()).bottom, jxh_screenWidth(), SPSBStarPageBottomViewHeight + jxh_safeInsets(spsb_keyWindow()).bottom)];
- _adBottomView.backgroundColor = spsb_FFFFFF_color(1.f);
- [_ad.splashView addSubview:_adBottomView];
-
- UIView *contentView = [[UIView alloc] init];
- contentView.backgroundColor = [UIColor whiteColor];
- [_adBottomView addSubview:contentView];
- [contentView makeConstraints:^(JXHConstraintMaker *make) {
- make.centerX.equalTo(self->_adBottomView);
- make.height.equalTo(106);
- make.top.equalTo(0);
- }];
-
- UIImageView *logo = [[UIImageView alloc] initWithImage:jxh_getImage(ad_logo)];
- [contentView addSubview:logo];
- [logo makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(0);
- make.centerY.equalTo(contentView);
- }];
-
- UIImageView *font = [[UIImageView alloc] initWithImage:jxh_getImage(ad_logo_font)];
- [contentView addSubview:font];
- [font makeConstraints:^(JXHConstraintMaker *make) {
- make.leading.equalTo(logo.trailing).offset(10);
- make.trailing.equalTo(0);
- make.centerY.equalTo(contentView);
- }];
- jxh_delayAction(1, dispatch_get_main_queue(), ^{
- [jxh_appDelegate() changeTabBarType:SPSBTabBarTypeHome];
- [self performSelector:@selector(skipAd) withObject:nil afterDelay:3];
- });
-
- }
- - (void)closeAD {
- [NSObject cancelPreviousPerformRequestsWithTarget:self];
- if (_ad) {
- [_ad removeSplashView];
- _ad = nil;
- [_adBottomView removeFromSuperview];
- [_adSkipButton removeFromSuperview];
- _adSkipButton = nil;
- _adBottomView = nil;
- }
-
- }
- - (void)skipAd {
- [self closeAD];
- [jxh_appDelegate() showHomePage];
- }
- #pragma mark - BUSplashAdDelegate
- /// This method is called when material load successful
- - (void)splashAdLoadSuccess:(BUSplashAd *)splashAd {
- debugLog(@"----------获取广告成功");
-
- [self splashAdDidLoad:_ad];
- }
- /// This method is called when material load failed
- - (void)splashAdLoadFail:(BUSplashAd *)splashAd error:(BUAdError *_Nullable)error {
- debugLog(@"-=-=-=-=-=--获取广告失败");
- [self closeAD];
- [jxh_appDelegate() showHomePage];
- }
- /// This method is called when splash view render successful
- - (void)splashAdRenderSuccess:(BUSplashAd *)splashAd {
-
- }
- /// This method is called when splash view render failed
- - (void)splashAdRenderFail:(BUSplashAd *)splashAd error:(BUAdError *_Nullable)error {
-
- }
- /// This method is called when splash view will show
- - (void)splashAdWillShow:(BUSplashAd *)splashAd {
-
- }
- /// This method is called when splash view did show
- - (void)splashAdDidShow:(BUSplashAd *)splashAd {
-
- }
- /// This method is called when splash view is clicked.
- - (void)splashAdDidClick:(BUSplashAd *)splashAd {
- debugLog(@"-=-=-=-=-=--点击了广告");
- [self closeAD];
- // [jxh_appDelegate() showHomePage];
-
- }
- /// This method is called when splash view is closed.
- - (void)splashAdDidClose:(BUSplashAd *)splashAd closeType:(BUSplashAdCloseType)closeType {
-
- }
- /// This method is called when splash viewControllr is closed.
- - (void)splashAdViewControllerDidClose:(BUSplashAd *)splashAd {
-
- }
- /**
- This method is called when another controller has been closed.
- @param interactionType : open appstore in app or open the webpage or view video ad details page.
- */
- - (void)splashDidCloseOtherController:(BUSplashAd *)splashAd interactionType:(BUInteractionType)interactionType {
- debugLog(@"-=-=-=-=-=--关闭广告详情");
- [jxh_appDelegate() showHomePage];
- }
- /// This method is called when when video ad play completed or an error occurred.
- - (void)splashVideoAdDidPlayFinish:(BUSplashAd *)splashAd didFailWithError:(NSError *)error {
-
- }
- @end
- SPSBOpenADManager *spsb_openADManager(void) {
- return [SPSBOpenADManager shareManager];
- }
|