iOS ‘windows‘ is deprecated: first deprecated in iOS 15.0

总结获取各个iOS版本中获取 keyWindow 的方法

1、‘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

//这是 iOS 13之前的写法,在iOS 13之后的版本会出现上面的方法被废弃的提示
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;

// iOS13的写法
UIWindow *keyWindow = [UIApplication sharedApplication].windows.firstObject;

2、‘windows’ is deprecated: first deprecated in iOS 15.0 - Use UIWindowScene.windows on a relevant window scene instead

// 到 iOS15 时,获取 keyWindow 的方法又有了改变,iOS13 的写法行不通了。因此会有上面的提示警告
// iOS15 获取 keyWindow 的写法
UIWindow *keyWindow = self.view.window.windowScene.keyWindow;

你可能感兴趣的:(ios,xcode,objective-c)