0
votes

I am making an app that has multiple usage cases. It has the main functionality (activated by pressing the app icon), then other subsets of the main functionality which are activated by a custom URL scheme.

To explain my problem, I should explain how I currently tell my app to behave differently.

I have been using: -(BOOL)application:didFinishLaunchingWithOptions:

grabbing the url from the options: [launchOptions objectForKey:[keyArray objectAtIndex:0]]

Now I parse that urlString and grab all of my launchType parameters, putting them in NSUserDefaults. Then I wait for my splash screen to come up, then it will tell my app how to behave.

This seemed okay at first, but then I realized that: if I deep-link into the app, and am presented with functionality B, then the app goes into the background, the next time the app take the foreground (no matter which way), it will display functionality B.

I was wondering if anyone had an idea about the standard practice, what methods do people usually use?

FYI, I am going to be trying to fix this problem by telling my navigationcontroller to popToRootViewController, when -(BOOL)application:application handleOpenURL: is called, UNLESS didFinishLaunchingWithOptions is called before it, in which case, just do what I had previously implemented.

1

1 Answers

2
votes

It sounds to me like there are a couple of things for you to consider about this approach.

First of all take a look at the UIApplicationDelegate documentation. -application:willFinishLaunchingWithOptions: warns:

If your app was launched to open a URL, you should examine the value of the UIApplicationLaunchOptionsURLKey key and return a Boolean value indicating whether your app can actually open the URL. You should not try to open the URL in this method. Instead, implement the application:openURL:sourceApplication:annotation: method in your app delegate and use that method to open the URL.

Looking at -application:openURL:sourceApplication:annotation: we see:

If your app had to be launched to open the URL, the app calls the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods first, followed by this method. The return values of those methods can be used to prevent this method from being called. (If the application is already running, only this method is called.)

Secondly it sounds like you are using NSUserDefaults to persistently store what should be a temporary state (if the app was launched via a url or not). Do you ever reset the values you set there or does launching the app via a url once leave it stuck always following that path.

Finally users have a reasonable expectation that apps will resume where they left off. Users will leave your app to respond to phone calls, text messages, notifications, external distractions, needs for other apps, and any number of other reasons. Refusing to allow them to return to where they left off when they resume/relaunch the app (not via a url) may produce a poor user experience.