Contents involved in this paper:

  1. In the iOS13UISceneDelegateThe changes brought about by;
  2. How do I configure it so that I don’t use the default in iOS13UISceneDelegate;

An overview of the

In iOS13, iPhone split screen is still not supported, which has brought about a change in App mid-life proxies in iOS development. Life cycle functions used to be managed by AppDelegate, but now not only can AppDelegate manage, SceneDelegate can also be used as a proxy for the App’s declaration cycle function, and it defaults to SceneDelegate in Xcode10. If both exist, SceneDelegate has a higher priority.

change

This change only involves the change of app state, that is, the statement period function of APP, such as WillEnterForeground, WillResignActive, DidEnterBackground, etc. DidFinishLaunchingWithOptions does not belong to the state of the App, accurately speaking, the website for the transition with words. The changes are as follows:

  • Before iOS13: THE UIKit framework sends notifications to app states when they changeUIApplicationDelegateOn the object;
  • In iOS13 and beyond, UIKit will preferentially send notifications when the state of your app changesSceneDelegateOn the object;

The result:

  • UIApplicationDelegateThere are only three functions left on the object:
  1. Loaded: didFinishLaunchingWithOptions
  2. Configuration will connect the scene: configurationForConnectingSceneSession
  3. After discarding the scene object: didDiscardSceneSessions
  • SceneDelegateTake over all app transition functions and scene connections:
  1. The scenario to connect: willConnectToSession
  2. Connected scenario: sceneDidDisconnect
  3. sceneDidBecomeActive
  4. sceneWillResignActive
  5. sceneWillEnterForeground
  6. sceneDidEnterBackground

Pay attention to

  1. IOS13 doesn’t necessarily mean split screen, doesn’t mean iPhone can use split screen, currently only iPad can use split screen;
  2. Select enable split screenSupports multiple windowsAnd configuration and support, iPad development is not discussed here, so the development details of the split screen function will not be launched;

Configuration of new project

In Xcode10, SceneDelegate is created by default and the corresponding configuration is generated in info.plist as follows:

Info. Plist is as follows

If you don’t want to use SceneDelegate, you can:

  1. Delete Scene Configuration from info.plist;

  2. Functions such as adding applicationWillEnterForeground AppDelegate;

- (void)applicationWillEnterForeground:(UIApplication *)application {
    NSLog(@"applicationWillEnterForeground");

}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    NSLog(@"applicationDidEnterBackground");

}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"applicationDidBecomeActive");

}

- (void)applicationWillResignActive:(UIApplication *)application {
    NSLog(@"applicationWillResignActive");

}
Copy the code
  1. AppDelegateaddUIWindowProperties;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
Copy the code

other

In fact, UISceneDelegate makes the code in the original AppDelegate simpler and is recommended. If the project already uses a custom AppDelegate to separate the transition function from the business function, ignore it.