Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Re-opening iOS app through Url Scheme - State Preservation

Tags:

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??

like image 745
Lyndsey Scott Avatar asked Apr 12 '13 14:04

Lyndsey Scott


People also ask

What is URL scheme in iOS?

A URL scheme allows you to launch a native iOS application from another iOS app or a web application. You can set options in the URL that will be passed to the launched application.

What is app URL scheme?

The app: URL scheme can be used by packaged applications to obtain resources that are inside a container. These resources can then be used with web platform features that accept URLs.

What are custom URL schemes?

Custom URL schemes provide a way to reference resources inside your app. Users tapping a custom URL in an email, for example, launch your app in a specified context. Other apps can also trigger your app to launch with specific context data; for example, a photo library app might display a specified image.


1 Answers

(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;
like image 81
Lyndsey Scott Avatar answered Oct 07 '22 02:10

Lyndsey Scott