How does iMessage preserve viewController state after view disappears? - ios

I observed that iMessage preserves last typed message in a chat even if I move to another chat and come back to it.
For eg. I am in Chat1 and typing. Then without sending the message I move to Chat2 and then come back to Chat1. Last typed message is still there.
If I understand correctly, when I press back button in Chat1, it should execute viewWillDisappear which should destroy all local elements.
Then how is last typed message still there?

iMessage is not the only app which does it. Whatsapp also does it. Even you open a chat in whatsapp scroll to older message->go back->and come again on the same chat. You will see the old state of chat.
The Recommended way to do it is App State Restoration if you want to store the whole state of your controller with more UI elements and values.
You can check following tutorial available for this..
https://www.raywenderlich.com/117471/state-restoration-tutorial
http://useyourloaf.com/blog/state-preservation-and-restoration/

Related

How iOS handles events that occurs just right before the background?

First of all I'd like to say sorry in case my question is dummy, I'm really new to iOS and what to understand how thing are going on. Imagine such a situation - user taps on home button and the app starts to collapse, but immediately after taping on home button user taped on some UI element. So, I'm wondering how the iOS will handle this? I tried to do some tests using breakpoints, but since it just test I can't be 100% sure. It seems that if the UI interaction event will happen before the system will call willResignActive then the event will be fully processed and if the system will call willResignActive first, then the even will be discarded and won't be handled at all. Is this correct, or I missed something? Thanks
First, why do you want to use this in your app? If a user presses a button exactly in this time, it's okay that the action is not handled.
The only thing you have to keep track of is that whenever the button gets pressed and let's say you store a file without a completion handler it could be that you present an alert which is saying that everything went well but you actually not saved the file because the user left the app in this time.
But since you're never doing critical actions without completion handlers, in my opinion, there's no need to make sure that this doesn't happen.
If I got you wrong, just comment!

What architecture can I use to change screens in Swift when there's an event outside of the current view?

For example, I have a Notification that occurs when there is an "unauthorized" error returned from the api server that should bring the user back to the login screen. This event could appear anywhere in the program.
Do I create a new viewless controller to manage states and have it monitor for this notification and then present the login view controller?
I'm thinking about push notifications too, received by the app delegate. Some of these may cause the data model to get updated and then the screen to change. Who should make the screen change? In the past I put all this in the AppDelegate. But there must be a more elegant way!
I also found out about FlowControllers. But they don't play nicely with Interface Builder, at least according to this solution.
Please let me know if you need more specific information about my project.

iOS Swift Briefly Display Info

I want to have some information drop down from the top of a view, stay on the screen for a second or two, and then go back up out of the view. I have search for displaying notifications and/or banners. All I get is either push notifications (which I don't need to use) or iAds banners.
I'm working on a barcode scanning app and I want to briefly show the value of the barcode shown without requiring the user to tap on anything. How can I accomplish this?
Don't use notifications and banners, because that might not work: the user can turn them off. In any case this is not a notification of anything, so it's a misuse of notifications.
Just do what you described, yourself: animate a view onto the screen, and then (in the animation's completion handler) use delayed performance to animate the view right back off the screen after a short delay.
You should use a view which manages its own state (INCOMING, STAY PUT, OUTGOING). This way you can reduce the memory footprint and many other bugs in the process. I coded something for a similar process. Check it out

Chromecast - return to homepage when done casting

I'm writing an iOS app that casts pictures. I want to make it in a way that when the user quits the picture viewing scene, it goes back to the homepage (the one displaying app's name) on the big screen. I've tried calling the stop method for mediaControlChannel and it's not going back to the homepage. So apparently this is not the one I'm looking for. So which method should I call to make it go back to homepage?
SDK doesn't have any understanding of your "homepage"; that is a concept in your app so you need to write your receiver so that if user ends the process of viewing picture, it switches to that page. Whether receiver on its own can determine that the above process has ended or sender has to signal the receiver depends on your application and its details but regardless, going to your home page is an action that you have to define and handle.

IOS Is there a way to send user to particular view after tapping "view" on notification?

I am using push notifications in my app and I would like to send user to particular view, not the view he last saw. Is it possible?
You need to implement the appropriate AppDelegate messages.
Specifically, you will receive the APNS payload on the application:didFinishLaunchingWithOptions:
You might also receive the payload in a different message, application:didReceiveRemoteNotification: if the application is active.
Then when you know that your app was launched because the user touched a notification, you can direct him to a specific view accordingly.
I don't think that you have control over what the user sees while app is starting app (opening animation). After the app is fully active, you can send him wherever you want to by opening proper view controllers, setting proper tab, etc...

Resources