UIAlertView
在iOS 9版本中已经废弃,无法在基于SceneDelegate
管理的应用程序中使用
一)不使用SceneDelegate管理window
UIWindow *window = UIApplication.sharedApplication.delegate.window;
二)使用SceneDelegate管理window
UIWindow *window = ((id<UIWindowSceneDelegate>)[UIApplication sharedApplication].connectedScenes.anyObject.delegate).window;
NSDictionary *infoDic = NSBundle.mainBundle.infoDictionary[@"UIApplicationSceneManifest"];
// 通过infoDic,判断是否使用UIScene
if (infoDic) {
// 通过supportsMultipleScenes,判断是否支持多个场景
if (UIApplication.sharedApplication.supportsMultipleScenes) {
// 获取所有已链接Scenes
NSSet <UIScene *> *connectedScenes = [UIApplication sharedApplication].connectedScenes;
for (UIScene *scene in (UIWindowScene *)connectedScenes.allObjects) {
UISceneActivationState activationState = scene.activationState;
// 通过activationState,获取当前场景window对象
if (activationState == UISceneActivationStateForegroundActive) {
UIWindow *window = ((id<UIWindowSceneDelegate>)scene.delegate).window;
}
}
}
}
网友评论