Open ziyilixin opened 4 years ago
兄嘚 解决了吗
因为创建的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];
//管理器这样使用没问题的;
@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; }
我来补充,二楼写得过于简略,影响发挥: 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];
} }
在iOS13上广告不显示,iOS13以下的系统上广告显示