iOS13适配

随着2019年苹果发布会的发布,iPadOS与iOS13也带来了新的架构体系,那就是以UIScene为核心的分屏概念。在iOS9之后,ipad不同的应用间是可以多开的,而在iOS13和ipadOS系统中,同一应用也支持多开。新系统之前,UIAppication管理者app和UI的生命周期,而新版本之后,UIAppication则更加专心的负责app的生命周期,而UI的管理则放在了UIWindowScene中,与之对应的是,UIAppication的Delegate中所有与UI有关的方法和属性都移除了(或者说不建议被使用)。

即使你的app没有适配分屏,但是在iOS13中也会被UIScene所管理,但是还会走原来的回调。

部分变化的API

当然,这只是一部分。

而,UIAppication中所有有关window的属性如:

@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));
@property(nonatomic,readonly) NSArray<__kindof UIWindow *>  *windows;

- (BOOL)sendAction:(SEL)action to:(nullable id)target from:(nullable id)sender forEvent:(nullable UIEvent *)event;

@property(nonatomic,getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible API_UNAVAILABLE(tvos) API_DEPRECATED("Provide a custom network activity UI in your app if desired.", ios(2.0, 13.0));

@property(readonly, nonatomic) UIStatusBarStyle statusBarStyle API_UNAVAILABLE(tvos) API_DEPRECATED("Use the statusBarManager property of the window scene instead.", ios(2.0, 13.0)); // default is UIStatusBarStyleDefault

@property(readonly, nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden API_UNAVAILABLE(tvos) API_DEPRECATED("Use the statusBarManager property of the window scene instead.", ios(2.0, 13.0));

@property(readonly, nonatomic) UIInterfaceOrientation statusBarOrientation API_UNAVAILABLE(tvos) API_DEPRECATED("Use the interfaceOrientation property of the window scene instead.", ios(2.0, 13.0));

都在新系统中废弃。

具体的可以去了解一下关于UIScene更多的知识这里不再多讲。

但是UIAppication给出两个属性:

#pragma mark -- UIScene --
// All of the currently connected UIScene instances
@property(nonatomic, readonly) NSSet *connectedScenes API_AVAILABLE(ios(13.0));

// All of the representations that currently have connected UIScene instances or had their sessions persisted by the system (ex: visible in iOS' switcher)
@property(nonatomic, readonly) NSSet *openSessions API_AVAILABLE(ios(13.0));

// returns YES if the application both declares multiple scene support in its info.plist and the executing environment allows multiple scenes for at least one system type. NO otherwise.
@property(nonatomic, readonly) BOOL supportsMultipleScenes API_AVAILABLE(ios(13.0));

可以看到我们得到的scene是一个集合.

那么我们如果在数据模型中要使用到showWindow属性的时候如何获取呢?

我的一个解决方法是hook UIWindow的这个方法:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;

1.记录操作window

在每一次点击UIView的时候,通过UIView的window属性获取当前操作的window,记录下来。

2.获取window

在获取window的时候遍历connectedScenes,如果只有一个scene处于前台,当前在前台的window处理事件的优先级最高,当做showWindow,其他的我们就用上次操作的window来处理事件。

你可能感兴趣的:(iOS13适配)