CoderZhuXH / XHLaunchAd

🔥The screen opening advertising solutions - 开屏广告、启动广告解决方案-支持静态/动态图片广告,mp4视频广告,全屏/半屏广告、兼容iPhone/iPad. 【 Github下载不了/下载慢 可以访问国内下载地址: https://gitee.com/CoderZhuXH/XHLaunchAd】
MIT License
3.69k stars 740 forks source link

iOS13广告不显示 #217

Open ziyilixin opened 4 years ago

ziyilixin commented 4 years ago

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

Panerly commented 4 years ago

兄嘚 解决了吗

lanligang commented 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];

lanligang commented 4 years ago

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

@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; }

295060456 commented 4 years ago

我来补充,二楼写得过于简略,影响发挥: 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; }