How to launch an app using NSURL and -openURL:? - ios

There are a few apps which I find very helpful and want to recommend to my users inside my app. If one such app is installed, and the user taps the button, I want to launch that app. Otherwise open the app page in the App Store app.
UIApplication provides a -canOpenURL: method which I think can be used to check if an app exists on the device. With -openURL: an app can be launched. But how do I construct an NSURL to launch an app?
The apps I want to refer to don't have any special registered URL scheme, at least not that I know of. All I know is their name and app ID.
Is that possible or must the developers of these apps update their apps to support custom URL opening schemes?

It is only possible to open the app by url in case it has known registered URL scheme (it may me your application or one of the existing iOS schemes)

Here is a list of public URL schemes. This however is just a fraction of what is out there in the market. It may however be helpful for you.

Related

How to get any App's Bundle ID or App ID in iOS

Is there a way to know any App's bundle ID or App ID which is running in the foreground? I have seen this feature in this App called Backbone, which asks user to open any App, press a button on their hardware (Which is a game controller, connected to iPhone via lightning connector) and then a link/shortcut to that App gets added in their App. It seems like they are able to establish a link between their App and other Apps, based on what I know so far it is not possible without knowing the Custom URL scheme of the App.
Anyone knows if there is another way it can be done?
Thanks in advance!
URL Schemes are the only way to communicate between apps. So, no, it's not possible to launch any other apps.
But it is possible to launch any app that registers a URL Scheme, whether it's Apple's, yours, or another developer's.
For more info, check this question discussions.

Kiosk App in iOS can we provide any identifer to that app to use from URL scheme.

I wanted, to give some identifier to the app that we create like a kiosk mode in iOS.
i.e. We make add to home screen and it has an icon on home page which browse further.
Is there any way, where I can give some identifier Name to that link of app getting created so that we can get that app access from our Native and we can provide URL Scheme for the same.
Thanks.
iOS will not give access of all the url schemas. You can refer this document where the url schemas for selected application is given :
http://wiki.akosma.com/IPhone_URL_Schemes#Phone
It may be that the only way you can achieve what you want to do is to build an app around an iOS UIWebView. You can then include the camera functionality directly in the app, although there can be issues as a UIWebview doesn't handle things like popups that Safari does.

How to get a list of your iphone apps

How can i get a list of all my iphone apps (even pointers for each app will be helpful)?
I'm developing an app which contain some screen that should have a list of all my installed apps (with their icon) and the option to select one to launch it in the future depends in other function of mine.
Thanks alot!
There's no way to accomplish this, because each app is sandboxed.
You would be able to determine if select apps are installed if they have custom URL schemes. For example, the Facebook app can be launched with the custom url scheme "fb://", but these aren't guaranteed to be unique, so a different app could use a scheme that's well known to belong to another app. Also not all apps have a custom URL scheme, and you would need some master list (that would need to be constantly updated to be accurate) to check for the presence of each. So you could maybe detect a select list of well-known apps with custom URL schemes, but never get a list of all of them.
If you just wanted to detect your own apps, you could have custom URL schemes that are almost certainly going to be unique set for each app, and check for those.
You could also jailbreak your device, but I'm assuming you want this functionality in an app that is distributed on the app store, so you wouldn't be able to add functionality that requires a jailbreak to work.
EDIT:
Here's an example showing detection of the Facebook app being installed:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]])
{
// Handle the Facebook app being installed
}
Note however, this won't give you any information about the app. Any app developer could add the "fb://" custom url scheme to their app, which would make this falsely detect it.
If you want to find lists of custom url schemes for iOS apps, just search in Google.
another way to look at this is to present the user with all of your app in the appstore. If they have any apps installed on their device then in iOS 7 they will see a button called "Open" next to each of them.
For example you can have a UITableViewCell or a UIButton that says "Checkout Our Apps". In the code you would add this.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://itunes.com/apps/sixaxisllc"]];
Replace SixAxis LLC with your iTunes developer name and when users click on it, it will launch AppStore app with only your apps are shown. (With Open or price amount next to each of them)
NOTE: test this on actual device and not in simulator
Because of the Sandboxed environment, all you can do is test if it you can open a custom URL.
Akosma Software maintains a list of popular Url on his wiki: IPhone URL Schemes.

How to force an iTunes URL to open in Safari on the iPhone?

I have the following URL which links to the product page of a Mac app. I'd like to provide this URL inside my iPhone app. However, it always launches the App Store and subsequently can't display the product because it's not an iOS app. How would I tell it to open in Safari? Is this even possible?
http://itunes.apple.com/us/app/appname/idxxxxxxxxx
Haven't found an answer, so opted for directing to Appshoper URL instead.

How iOS handle URL scheme duplication?

If 2 other app register same url scheme, how iOS handle this?
The iOS Documentation reads:
Note: If more than one third-party app registers to handle the same URL scheme, there is currently no process for determining which app will be given that scheme.
The OSs behaviour is undefined if there are two apps registered for an URL scheme, therefore you should try to define a handler that is specific for your app to avoid this situation (e.g. awesomeMapsApp:// instead of maps://).
Actually it can be really problematic. For example, til' March 2016, an app called Grabb handles PayPal schemes so that if your app tries to open PayPal (with all the security nonce etc. within the call) it launches Grabb instead, and you can do nothing about it. Even with the openURL alertView added in iOS 9, it can still be a big security issue.
Here is what I have tested:
iOS 5: the first installed app will be chosen. If you delete first installed app, then the others will not launch unless you install again.
iOS 6: the lastest installed app will be chosen. If you delete the lastest installed app, then the previous installed app will be chosen.
It will present an UIActionSheet view allowing the user to choose which app to launch (good example are apps that handle .doc files). That's where the icon you specify is used - on the action sheet buttons when it's shown to the user

Resources