Louis
Louis

Reputation: 123

CanOpenURL without add LSApplicationQueriesSchemes

I have a question that I wanna open other apps in my app,
(a MDM Like App),
but after iOS 9,
using CanOpenURL to check other apps need to add Schemes in LSApplicationQueriesSchemes,
I get my apps list on websrevice so I can't add them into plist,
is there any solution to use CanOpenURL to check other apps is install or not without add scheme in LSApplicationQueriesSchemes?

Upvotes: 1

Views: 3999

Answers (1)

Andreas Oetjen
Andreas Oetjen

Reputation: 10209

You can use UIApplication.open(_:​options:​completion​Handler:​) whithout specifying the URLS in LSApplicationQueriesSchemes. That key is only used for can​Open​URL(_:​). See Apple's documentation here:

... Unlike this method, the open​URL(_:​) method is not constrained by the LSApplication​Queries​Schemes requirement. That method works if an app is available to open the URL, whether or not you have declared the scheme.


Update

So if you need canOpenURL, you will also need those LSApplication​QueriesSchemes entries in the .plist, otherwise canOpenURL will always return false. This restriction has been implemented in iOS 9 (I think) to prevent malicious apps from sniffing around the installed phone.

Since there is no way to add entries at runtime and wildcards aren't possible, the only solution is to directly call openURL and check if it was successful or not. If your webservice and MDM guarantees that the apps being called are installed, this could be a viable work-around.

You could also implement something like x-callback. Think of the following:

  • The central (MDM-like) app registers a URL like "register-app://" where other apps can register themself with their own (callback) URL Scheme
  • The other app calls "register-app" and provides it's own (callback-) scheme
    • It has to be started manually once to do so
  • The MDM-like app stores the "callback-URLS" in a database
  • The MDM-like app now directly uses openURL
  • There is no need for the webservice any more

Or your MDM (the real MDM) could send a push notification to inform about newly installed apps and their URL scheme.

Nevertheless, it's all just tricks to circumvent the restrictions apple thought of...

Upvotes: 2

Related Questions