简体   繁体   中英

Re-opening iOS app through Url Scheme - State Preservation

I'm sending the user from my app to a browser then returning them to the app through my custom URL. The problem is: All of my instance variables are empty once I return! The interface is preserved (as expected since I used the Storyboard), but the values (of the textfields, instance variables, etc.) are inaccessible...they return null.

What's going on??

(It's been a while since I had this problem, but here's what I think happened…)

While handling the return URL's call in my app delegate's openURL method, I attempted to call my view controller's method in response and did so by creating an instance of that method's view controller. Since I didn't access the current instance, I essentially created a blank, second instance of that view controller.

In this case, I ended up using an NSNotification instead of directly calling the method. And I definitely think this is the most elegant solution.

But what I also could have done in retrospect, is access the current instance of the view controller which also happened to be the root view controller using:

UIViewController *controller = self.window.rootViewController;

The response from the calls in the app delegate should preferably not call for any specific view controller, one of the following should be preferably used to modify data-

1.Blocks

2.NSUserDefaults or CoreData Database

3.Notifications

4.Shared Singleton instances

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM