How to use UIScene lifecycle with NativeScript

UIScene lifecycle will soon be required for all iOS apps. Learn how to adopt it in your NativeScript app today.

Nathan Walker
Posted on

Adopting the iOS UIScene lifecycle will soon be a requirement for all iOS apps. This guide walks through how to switch your NativeScript app today.

Most details are outlined in the multi-window docs here.

The red warning

If you ns open ios and run your NativeScript iOS app inside Xcode today, you may see this red warning in the Xcode console.

iOS UIScene Warning

This warning is telling you that your app is using the old lifecycle and that you need to adopt the UIScene lifecycle.

This has actually been recommended for several years since iOS 13 (2019) and it's been a slow deprecation cycle which is finally coming to an end. Soon, all iOS apps will be required to use the UIScene lifecycle and the old lifecycle will no longer be supported.

Support UIScene in Info.plist

To add UIScene support, you can add the following keys to your App_Resources/iOS/Info.plist file.

xml
<key>UIApplicationSceneManifest</key>
<dict>
  <key>UIApplicationPreferredDefaultSceneSessionRole</key>
  <string>UIWindowSceneSessionRoleApplication</string>
  <key>UIApplicationSupportsMultipleScenes</key>
  <true/>
  <key>UISceneConfigurations</key>
  <dict>
    <key>UIWindowSceneSessionRoleApplication</key>
    <array>
      <dict>
        <key>UISceneConfigurationName</key>
        <string>Default Configuration</string>
        <key>UISceneDelegateClassName</key>
        <string>SceneDelegate</string>
      </dict>
    </array>
  </dict>
</dict>

Use NativeScript 9+

Make sure your app is using NativeScript 9 or later and you're done.

The addition of those keys to you Info.plist is all that's needed and NativeScript 9 will begin using the Scene lifecycle on iOS.

Nothing else changes with how your app behaves. The same event wirings work as before like these for example:

ts
Application.on(Application.resumeEvent, function (args) {
    console.log('app resumed')
});

Application.on(Application.suspendEvent, function (args) {
    console.log('app suspended')
});

But now your app is using the new lifecycle and the red warning in Xcode is gone.

You also have more options now. You can also listen to Scene lifecycle events as mentioned in the multi-window docs.

Future Directions

The TSC (Technical Steering Committee) is discussing additional adjustments to Application.on listeners and behavior for a future release which may expand to include Android multi-window behaviors.


More from our Blog