iOS13下新API和出现的问题

1.iOS13获取keywindow,不推荐使用 [UIApplication sharedApplication].keyWindow,过期了,

@property(nullable, nonatomic,readonly) UIWindow *keyWindow API_DEPRECATED("Should not be used for applications that support multiple scenes as it returns a key window across all connected scenes", ios(2.0, 13.0));

需要使用

[UIApplication sharedApplication].windows[0];

2.present一个控制器后的keywindow,和页面前的,不一定是一个window。需要页面展示完成获取当前页的主窗口,进行操作。

//iOS13下面不推荐的方法
[self presentViewController:navContoller animated:YES completion:NULL];
 UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
//不一定是页面展示完成的window,故view不一定展示
[keyWindow addSubview:view];

//推荐的做法
[self presentViewController:navContoller animated:YES completion:^{
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow addSubview:view];
 }];

。。。待续

你可能感兴趣的:(iOS13下新API和出现的问题)