Is it safe to remove SceneDelegate from Existing project? - ios

I have my project which supports minimum ios version 12.4 and I'm using swift 5.2 in my project. To suuport Zoom SDK I need to remove sceneDelegate.swift file and SceneManifest from info.plist. Is it safe to remove sceneDelegate from existing project?
In my thought AppDelegate will be responsible for the application lifecycle and setup. The SceneDelegate will be responsible for what is shown on the screen (Windows or Scenes) handle and manage the way your app is shown.So will there be any issues in UI Flow of my APP if I remove Scene Delegate?
If I remove sceneDelegate how will handle app Foreground and Background Events?

Yes it 100% safe to remove SceneDelegate from your iOS app.
Please refer below steps to remove it from your app
Remove SceneDelegate.swift file
Remove Application Scene Manifest from Info.plist file
Add var window: UIWindow? to AppDelegate.swift
Replace #main with #UIApplicationMain
Remove UISceneSession Lifecycle ( functions ) in AppDelegate
After deleting scene delegate you would not able to do following
In iOS 13 and later, users can create multiple copies of your app’s UI
and toggle between them in the app switcher. On iPad, users can also
display one copy of your app’s UI side by side with another copy. For
each copy of your app’s UI, you use a scene object to manage the
window, views, and view controllers that present the UI onscreen
https://developer.apple.com/documentation/uikit/app_and_environment/scenes/specifying_the_scenes_your_app_supports
To answer you question to regarding view life cycle please refer this - https://www.appypie.com/scene-delegate-app-delegate-xcode-11-ios-13#:~:text=On%20iOS%2013,at%20a%20time.

Related

Is SceneDelegate mandatory? [duplicate]

This question already has answers here:
Opt out of UISceneDelegate/SwiftUI on iOS
(6 answers)
Closed 3 months ago.
The question says it all.
There's the following line in apple documentation,
Scenes are opt in, but you must support them if you want to display
multiple copies of your app’s UI simultaneously.
It's not mentioned whether the SceneDelegate is mandatory or optional or a recommendation (I'm aware that the SceneDelgate is used to handle the lifecycle of the scene).
In a iOS 13+ device, can I create an app without SceneDelegate?
I defined the UIWindow variable in the AppDelgate and set the ViewController in application(didFinishLaunchingWithOptions), like before iOS 13. But that doesn't work and displays a blank screen.
And thus, this question. Is Scenedelgate mandatory even if we don't opt for multiple scenes?
Here's my observation:
Multiple scenes are optional. But you still have to support at least
one scene... and for that, SceneDelegate is mandatory.
If I'm wrong and SceneDelegate is optional (like described in this stackoverflow post), please help with the flows.
In a iOS 13+ device, can I create an app without SceneDelegate?
Yes. All apps do have scenes, but if you go with the app-delegate-only architecture, a single UIWindowScene will be created behind the scenes (pun intended). The app will run perfectly well on both iPhone and iPad, with all the usual lifetime events arriving as usual into the app delegate (though I do not know what will happen on Apple Silicon).
I defined the UIWindow variable in the AppDelgate and set the ViewController in application(didFinishLaunchingWithOptions), like before iOS 13. But that doesn't work and displays a blank screen.
This is because you did not correctly convert from the scene delegate architecture, which is provided by the app template you started with, to an app delegate architecture. Basically, you've left pieces of the scene delegate architecture lying around. Perhaps you did not delete all references to the scene delegate; perhaps you forgot to delete the UIApplicationSceneManifest entry from the Info.plist. Whatever the reason, the result is that the runtime thinks this app still uses scene delegate architecture, and it then fails to find certain pieces that it's looking for and shows the blank screen.
So, just to sum up what to do when you've started with the built-in app template:
Delete the SceneDelegate.swift file.
In the App Delegate, delete the two UISceneSession methods.
In the App Delegate, add a window reference as an instance property: var window: UIWindow?
In the Info.plist, completely delete the entire UIApplicationSceneManifest entry (and save).
Profit.

Using showBluetoothAccessoryPicker causes SceneDelegate presenting errors

I currently have an app that will try to automatically discover a MFi bluetooth device.
The only way is to use the ExternalAccessory framework, as CoreBluetooth only files Ble devices.
Right now I have a button that executes:
EAAccessoryManager.shared().showBluetoothAccessoryPicker(withNameFilter: nil) { error in }
In order for the picker to appear, I need to add var window: UIWindow? inside my AppDelegate
So far this works. The picker shows, and will list the device I want to connect to. However When I try clicking the device for it to pair, I get this message:
2020-11-11 14:07:16.694761-0700 BT[500:48034] [Presentation] Attempt to present <UIAlertController: 0x105013a00> on <_TtGC7SwiftUI19UIHostingControllerV2BT11ContentView_: 0x104a0a510> (from <_TtGC7SwiftUI19UIHostingControllerV2BT11ContentView_: 0x104a0a510>) which is already presenting <UIAlertController: 0x105052800>.
Which does make sense. Currently the picker is presenting and then another alert is trying to be displayed to validate the pin and pair.
But if I delete the Application Scene Manifest in the info.plist, delete the SceneDelegate and remove all UISceneSession Lifecycle functions in the AppDelegate, it works..
The issue is I need the SceneDelegate as it's a swiftUI app and will fail to run otherwise.
Has anyone ran into this issue before?

SwiftUI 2 lifecycle - handle custom URL scheme

Until now we were able to handle custom URL schemes that launch the app using AppDelegate or SceneDelegate. But how is this possible using the new lifecycle?
I tried adding an #UIApplicationDelegateAdaptor with the application:openURL:options: function but that is never called. The closest I've got is using the Environment's scenePhase but that only tells the state of the scene (active, background etc.), not the incoming URL.
You can use the onOpenURL(perform:) modifier either in the body of you App or Scene or on views in your hierachy. The modifier gets called multiple times as well, so you could set the state for each view individually. With that your AppDelegate no longer needs to know your whole navigagion, which is great.

Can't understand what UIScenes are

I can't find a clear definition of what UIScenes are
Are they just for handling the background calls? Are they like a ViewController? Do we use them often or nah?
The biggest thing is that scenes set up multiple window support. It is also useful for SwiftUI.
The SceneDelegate controls what is displayed on the screen "to manage life-cycle events in one instance of your app's user interface.", while the AppDelegate controls your entire app life-cycle.
Read the App and Environment Article and scenes from Apple instead of UIScene documentation.
Scene:
Scene, Manage multiple instances of your app’s UI simultaneously, and
direct resources to the appropriate instance of your UI.
We had only one scene back then before iOS 13, So the only thing we need to run ViewControllers simultaneously was multiple Windows on top of each other. But now, each application can have multiple instances running at the same time! Each scene has its own state and it might be in the foreground while others are in the background or are suspended, while Window was completely dependent on the application itself.
Imagine we have 2 view controllers (consider there are no scenes) running on the left and right side of the device and then we need to show a banner. Using the old window method will show the banner on both of them! And if you need to pick one, you may end up finding the correct controller and presenting the banner on it.
So apple introduced Scene, a container for each separate instance of the app. So you can manage each one separately and each of them acts as a separate app. It has its own windows and controllers. But all of them are managed by a single object, UIApplication.shared and it has a delegate to handle general events (usually from outside of the app) and entire application life cycle.

Should my app be updated to Scene Delegate

Should my app be updated to Scene Delegate from App Delegate. My app supports ios 13.0 and up
first you have to understand what is difference
You could think of them as the global and private versions. One is shared and the other is limited to the individual owner. In a way, they are exactly what you would expect by the names.
Multi-window support is happening
Next time you create a new Xcode project you’ll see your AppDelegate has split in two: AppDelegate.swift and SceneDelegate.swift. This is a result of the new multi-window support that landed with iPadOS, and effectively splits the work of the app delegate in two.
From iOS 13 onwards, your app delegate should:
Set up any data that you need for the duration of the app.
Respond to any events that focus on the app, such as a file being shared with you.
Register for external services, such as push notifications.
Configure your initial scenes.
In contrast, scene delegates are there to handle one instance of your app’s user interface. So, if the user has created two windows showing your app, you have two scenes, both backed by the same app delegate.
Keep in mind that these scenes are designed to work independently from each other. So, your application no longer moves to the background, but instead individual scenes do – the user might move one to the background while keeping another open.
at last I will say that you can go with Scene Delegate
Courtesy of https://www.hackingwithswift.com/articles/193/whats-new-in-ios-13

Resources