Adopting Scenes in iPadOS | raywenderlich.com

In this Adopting Scenes tutorial, you’ll learn how to support multiple windows by creating a new iPadOS app. You’ll also learn how to update existing iOS 12 apps to support multiple windows.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/5814609-adopting-scenes-in-ipados
1 Like

Hi Mark!

I’m just in the middle of this tutorial but I noticed something at the beginning that is not right; under the UIWindowSceneDelegate section, you mention:

UIWindowSceneDelegate is a subclass of UISceneDelegate

which is incorrect as both of these are actually protocols, I wonder if:

UIWindowSceneDelegate is a delegate protocol that extends from UISceneDelegate

makes more sense…

That’s all by now, keep it up with these great tutorials! :metal:

@iosendava - sorry for the delayed reply. Great catch! I’ve updated the tutorial. Thanks for the feedback!

Hi Mark! I use NSManagedObjectContextObjectsDidChangeNotification and NSManagedObjectContextDidSaveNotification to keep all of the complex views of my Core Data application up to date. If a view is not onscreen, I set bools so that when it is back on screen it will update only as much as needed. I have noticed that when a scene is in the background, it still responds to these notifications from the NSNotificationCenter. I will not update the view at all while a scene is in the background, but is it still okay to process these notifications in iOS 13 for a scene that is in the background? I feel like I need to do this because, with multiple scenes, if I don’t do this, I will need to reload entire controllers that might not need reload, and might cause the user to lose their place, when the scene becomes active again. I saw in the tutorial about updating the snapshot, and that would be a nice next step - the app is so complex that it might be a while before I can get that implemented. But my main questions are 1. will Apple allow scenes in the background to receive and respond to UINotificationCenter notifications (it is technically possible, but will the app be rejected or killed because of this) and 2. is this a good practice – and if not, how else can I keep complex core data views in sync for background scenes, not so much the snapshot but the actual scene when it becomes active again, without reloading everything completely?

Hi @inphilly.

Scenes, as long as they are still active in memory, should be able to respond to notifications while in the background. I have not seen any rule or guideline from Apple that would indicate you need to stop listening to notifications when a scene goes to the background. I don’t see any issue with continuing to listen and respond to these notifications in this scenario. Just be aware that the snapshot model is the one that Apple has created for this purpose.

Great question, and good luck!

Thank you so much @ski081. That is immensely helpful. I just need one clarification - when you say that “the snapshot model is the one that Apple has created for this purpose”, what do you mean? Do you mean that in addition to the way I am currently responding to notifications in the background that I should also be updating the snapshot? Or should the way I am currently responding to notifications be changed somewhat to use the “snapshot model”?

I played with it a little yesterday and allowed my notifications to actually update the UI for a view that was in focus within a scene that was in the background, with no errors (this is actually a change for what I was previously doing, which was only setting flags for a scene that was in the background). Then I called the API to update the snapshot for that scene, and it did. I didn’t have to have send any additional information for this to happen since the scene UI was already updated. I was hoping that this was the correct way to do things; and based on the first part of your answer, I think it may be correct, but the last part of your answer threw me off a little.

Hi, @inphilly. That’s what I meant. Wherever possible, you should be using the snapshot API to update your views in the background. Sounds like that’s exactly what you’re doing. Sorry if that didn’t make sense from my previous comment.

Good luck!

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!