2

I was playing Epoch 2, and after I had installed Epoch 1, Epoch 2 said something like "okay, I see Epoch 1, here are free weapons for you".

How can I do something like this -- detecting the installation of another app -- and what are the limitations of this mechanism?

jscs
  • 63,694
  • 13
  • 151
  • 195
Oleg Sobolev
  • 3,286
  • 2
  • 16
  • 29

1 Answers1

1

An app can register custom URL handlers so that the system can direct certain type of requests directly to them.

A common example would be something like

appname://

or if an app has an associated facebook app it will usually handle facebook redirects to itself with its facebook app id which would look like

fb37238917293124:// (where the numbers are just the app ID)

Knowing an app's URL scheme will allow you to see if the app is installed on a given device by invoking the UIApplications canOpenURL method.

It would look like this:

BOOL twitterInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]];
Dima
  • 23,484
  • 6
  • 56
  • 83
  • Thank so much! For example, `twitterInstalled` will be YES if twitter app was killed by user? – Oleg Sobolev Mar 03 '14 at 20:04
  • And about this URLs, they are public for (popular) apps? – Oleg Sobolev Mar 03 '14 at 20:05
  • 1
    They're not always public, I could see where some devs would want to have URL functionality for non-public usage, (ie generating "deep application links") not necessarily to have a third party communicate. Also, not all applications will have them so you will be out of luck finding every installed app. – Daddy Mar 03 '14 at 20:08
  • Thanks, @JustinAmberson! Thats what i was searching for. – Oleg Sobolev Mar 03 '14 at 20:11
  • 1
    If you can get ahold of the IPA for an app you can extract it and get any custom URL schemes out of its plist file. They will be in the `CFBundleURLTypes` key, within `CFBundleURLSchemes`. Also, to test any custom schemes manually you can just paste them into the safari address bar on your phone and see if you get redirected into the app. For example, typing in `twitter://` into safari should redirect you into the Twitter app. – Dima Mar 03 '14 at 20:15
  • Can you post where and how should i add this URL into my app? @Dima – Oleg Sobolev Mar 03 '14 at 20:24
  • Do you mean registering your own custom URL scheme? – Dima Mar 03 '14 at 20:50
  • Refer to "Register Custom URL Schemes" in the [iOS Programming docs here](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW20) – Dima Mar 03 '14 at 20:52
  • Does this still work? I heard Apple made it so I can't just check all the different URLs. – Joshua Dance Apr 14 '17 at 16:18
  • It still works but you'll need to add `LSApplicationQueriesSchemes` to your plist. [Documentation](https://developer.apple.com/reference/uikit/uiapplication/1622952-canopenurl) – Dima Apr 14 '17 at 18:57