How to Add SceneDelegate to an Existing Storyboard Project in XCode

I have an old project previously built on IOS12 and now trying to add new features on IOS 13. One of the things I’m trying to wrap my head around before I start adding new functionalities to my app is the introduction of UIWindowScene and the support for multiple window for iOS and iPadOS.

What is UIWindowScene? As per the documentation – this is an object that manages one instance of your app’sUI, including one ore more windows that is displayed from that scene.

Before iOS 13, the AppDelegate is the starting point of an App. It was in charge of setup, state handling, and other logic as such as below:

  • setup first view controller – root view controller
  • configure app settings and startup components
    • logging
    • cloud services
    • persistent container
  • register push notification handlers and respond to push notifications sent to the app
  • respond to app lifecycle events
    • entering background
    • resuming app
    • existing app

My didFinishLaunchingWithOptions method implemented on the AppDelegate looks like this.

self.window object on the snippet above is a property of the AppDelegate and is the only one window my app uses. It manages the app’s UI, dispatch events to views and the main backdrop to display the app’s content.

On iOS 13, the AppDelegate is responsible for the initial setup only. The SceneDelegate takes over some of it’s roles, one of which is the window and is replaced by a scene. An app can now have more than one instance of the window/scene. So now you can have an app with multiple scenes.

For example for a word processor app could have every text document as a scene.

Now that the concepts has been discussed and hopefully clear. The following files on my existing project needs to be modified.

  • Adding a SceneDelegate class
    • Either create a new class SceneDelegate and paste the boiler plate code or create a new project on Xcode and copy the SceneDelegate from that project.
  • Updating the AppDelegate class
    • Existing implementation methods can be removed and add the two scene related implementation methods
  • Updating the info.plist file
    • for this one click on + icon the last item of the info.plist then choose Application Scene Manifest
    • Expand that and replicate the options as per the screenshot.

Fingers crossed all changes right, build your app. Get that sweet Build Succeeded message. Your app is now running on its own instance of the window.

Troubleshooting pod install Error on CocoaPods

Going through the Getting Started guide for Firebase I encountered this error ‘JSON::ParserError – 767: unexpected token at ‘ and thought to blog and share how to fix it.

I went to the Xcode project directory in the terminal and ran

pod init

Then I defined the PodFile spec

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'Firebase Getting Started' do
  # Comment the next line if you don't want to use dynamic frameworks
  #use_frameworks!

  # Pods for Firebase Getting Started
  pod 'Firebase/Analytics'
  # Add the pods for any other Firebase products you want to use in your app
  # For example, to use Firebase Authentication and Cloud Firestore
  pod 'Firebase/Auth'
  pod 'Firebase/Firestore'

end

But when I ran

pod install

I encountered this error

[!] Oh no, an error occurred.

Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=767%3A+unexpected+token+at+%27%27&type=Issues

If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new

Be sure to first read the contributing guide for details on how to properly submit a ticket:
https://github.com/CocoaPods/CocoaPods/blob/master/CONTRIBUTING.md

Don't forget to anonymize any private data!

Looking for related issues on cocoapods/cocoapods...
 - [1.9.2] Error during pod install JSON::ParserError - 767: unexpected token
   https://github.com/CocoaPods/CocoaPods/issues/9814 [open] [31 comments]
   8 hours ago

 - https://github.com/CocoaPods/CocoaPods/search?q=767%3A+unexpected+token+at+%27%27&type=Issues
   https://github.com/CocoaPods/CocoaPods/issues/9777 [closed] [3 comments]
   2 weeks ago

 - Error during pod install: Encountered an unknown error (783: unexpected token at
   https://github.com/CocoaPods/CocoaPods/issues/9672 [closed] [92 comments]
   22 hours ago

and 12 more at:
https://github.com/cocoapods/cocoapods/search?q=767%3A%20unexpected%20token%20at%20%27%27&type=Issues&utf8=?

[!] Automatically assigning platform `iOS` with version `13.5` on target `Firebase Getting Started` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.

After checking the issues. It turns out the cocoapods repo cache on my machine somehow got corrupted. To fix the error I simply deleted the cache.

sudo rm -rf ~/.cocoapods/repos

And running pod install after that worked.