IOS 13使用过程的一些变化
程序员文章站
2022-03-30 09:04:20
...
1.首先,创建工程的时候,多了SceneDelegate类,主要给之前的AppDelegate类分担了UI方面的操作。
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
}
2.发现常用的[UIApplication sharedApplication].keyWindow语句出现警告:
'keyWindow' is deprecated: first deprecated in iOS 13.0 - Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes
该怎么解决呢?搜索了一些文章,一般都是给的这个方法
UIWindow* window = nil;
if (@available(iOS 13.0, *))
{
for (UIWindowScene* windowScene in [UIApplication sharedApplication].connectedScenes)
{
if (windowScene.activationState == UISceneActivationStateForegroundActive)
{
window = windowScene.windows.firstObject;
break;
}
}
}else{
window = [UIApplication sharedApplication].keyWindow;
}
测试发现不对啊,没有作用,后来firstObject改成lastObject后,能达到效果,暂时还没找到原理,先记个flag。