Scrungepipes
Scrungepipes

Reputation: 37581

Is it possible to determine if an application has been launched by the user or via a URL at the point didFinishLaunchingWithOptions is called?

Is it possible at the time didFinishLaunchingWithOptions is invoked for me to know how the app was launched?

My app can be launched either by the user directly or by clicking on a url in an SMS.

When the app is launched it connects to a server and I'm starting that connection asynchronously in didFinishLaunchingWithOptions.

If the app is launched by clicking on its icon it connects to the server to see if there is anything for it to download. But if it is launched via a URL in an SMS then there is some data appended to the url which must be transmitted to the server.

However when the app is launched via a URL then openURL:url sourceApplication:sourceApplication annotation:annotation (which is how I obtain the url payload) is called AFTER didFinishLaunchingWithOptions.

Is it possible at the time didFinishLaunchingWithOptions is invoked for me to know how the app was launched? So that I know if via the user I will start the connection, otherwise if via a URL I won't and will wait until openURL::: gets called and do it then.

Upvotes: 1

Views: 237

Answers (1)

Firoze Lafeer
Firoze Lafeer

Reputation: 17143

In the options dictionary, you will have the UIApplicationLaunchOptionsURLKey which is the URL that caused your app to be launched. And you also have the UIApplicationLaunchOptionsSourceApplicationKey which tells you which application tried to open that URL.

Both of those should be populated in the case that your app was launched from the SMS.

I hope that helps.

Upvotes: 1

Related Questions