XHLaunchAd icon indicating copy to clipboard operation
XHLaunchAd copied to clipboard

iOS13广告不显示

Open ziyilixin opened this issue 5 years ago • 4 comments

在iOS13上广告不显示,iOS13以下的系统上广告显示

ziyilixin avatar May 11 '20 12:05 ziyilixin

兄嘚 解决了吗

Panerly avatar Aug 04 '20 01:08 Panerly

因为创建的window 没有添加场景的原因 UIWindowScene
-(void)scene:(UIWindowScene *)scene API_AVAILABLE(ios(13.0)){ _window.windowScene = scene; }

window的这个属性不设置就会出现 显示不出来,希望作者适配一下 使用了 SceneDelegate 的情况; 如果没有适配的话可以改一下源码中的 监听 XHLaunchAd 这个文件中 添加 -(void)scene:(UIWindowScene *)scene API_AVAILABLE(ios(13.0)); 此方法

修改 +(void)setWaitDataDuration:(NSInteger )waitDataDuration; +(XHLaunchAd *)setWaitDataDuration:(NSInteger )waitDataDuration{ XHLaunchAd *launchAd = [XHLaunchAd shareLaunchAd]; launchAd.waitDataDuration = waitDataDuration; return launchAd; }

在 iOS 13 中 监听 UISceneWillConnectNotification 不在iOS 13 中依然监听 启动页的启动,然后 _scene = note.object; //在 iOS 13 里面 而且使用了 SceneDelegate 请求广告前需要这样设置

XHLaunchAd * ad = [XHLaunchAd setWaitDataDuration:2]; [ad scene:_scene];

lanligang avatar Aug 12 '20 08:08 lanligang

//管理器这样使用没问题的;

@implementation AdManager{ UIWindowScene _scene API_AVAILABLE(ios(13.0)); } -(instancetype)init{ self =[super init]; if (self) { if(@available(iOS 13.0,)){ [[NSNotificationCenter defaultCenter]addObserverForName:UISceneWillConnectNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { self->_scene = note.object; [self requestLaunchAd]; }]; }else{ [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidFinishLaunchingNotification object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) { [self requestLaunchAd]; }]; } } return self; }

lanligang avatar Aug 12 '20 08:08 lanligang

我来补充,二楼写得过于简略,影响发挥: 1、不要用pod 集成 ,直接手动集成于工程,并更改源代码: @implementation XHLaunchAd里面 增加方法: -(void)scene:(UIWindowScene *)scene{ _window.windowScene = scene; } 并将此暴露于.h

2、在 @implementation SceneDelegate里面 static SceneDelegate *static_sceneDelegate = nil; +(SceneDelegate *)sharedInstance{ @synchronized(self){ if (!static_sceneDelegate) { static_sceneDelegate = SceneDelegate.new; } }return static_sceneDelegate; }

-(instancetype)init{ if (self = [super init]) { static_sceneDelegate = self; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noti1:) name:UISceneWillConnectNotification object:nil]; }return self; }

-(void)noti1:(NSNotification *)notification{ self.windowScene = notification.object; }

  • (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {

    //在这里手动创建新的window if (@available(iOS 13.0, *)) { self.windowScene = (UIWindowScene *)scene;

      XHLaunchAd * ad = [XHLaunchAd setWaitDataDuration:2];
      [ad scene:self.windowScene];
    
      [self.window setRootViewController:CYLMainRootViewController.new];
      [AppDelegate.sharedInstance setUpNavigationBarAppearance];
    
      [self.window makeKeyAndVisible];
    

    } }

JobsKits avatar Oct 11 '20 11:10 JobsKits