Url scheme : Open app or Appstore from mail - objective-c

I'm creating an application where users can share data by sending emails to each other.
In this mail there is a link to my app (I created an URL scheme for my app)
But, if the users doesn't have my application on his iPhone, then when he clicks on the link, nothing happens.
My question : How could I do to launch my app when the application is installed on the user's iPhone and launch the Appstore or a website if this application is not installed
Thank you

canOpenURL is what you're looking for.
Here is an example for launching twitter app:
NSURL* twitterURL = [NSURL URLWithString:[NSString stringWithFormat:#"twitter:#%#", twitterUser]];
if ([[UIApplication sharedApplication] canOpenURL:twitterURL]) {
[[UIApplication sharedApplication] openURL:twitterURL];
} else {
NSURL* url = [NSURL URLWithString:#"http://itunes.apple.com/us/app/twitter/id333903271?mt=8"];
[[UIApplication sharedApplication] openURL:url];
}
EDIT
If you want do do this from a webpage or html email, you find your answer here:
https://stackoverflow.com/a/627942/550177
and here:
https://stackoverflow.com/a/1109200/550177

Related

How do I open another application with tvOS?

Does UIApplication:openURL work?
NSString *iTunesLink = #"http://www.youtube.com/watch?v=TFFkK2SmPg4";
BOOL did = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
This does nothing.
I assume you're wanting to test a Custom URL Scheme. You will want to use canOpenURL to see if the URL can be opened first. canOpenURL returns a BOOL value indicating whether or not the URL’s scheme can be handled by some app installed on the device. If canOpenURL returns YES then you would continue to open the URL with openURL.
YouTube links open the YouTube app by default on iOS devices. This behavior is not yet testable on the new Apple TV as YouTube's app is not accessible in the tvOS beta.
Here's an example of how to use canOpenURL to see if Facebook is installed on an iOS device using its Custom URL Scheme:
Obj-C:
// Check if FB app installed on device
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"fb://profile/355356557838717"]];
}
else {
// FB not installed
// Do something else
}
Swift:
// Check if FB app installed on device
if UIApplication.sharedApplication().canOpenURL(NSURL(string:"fb://")!) {
UIApplication.sharedApplication().openURL(NSURL(string:"fb://profile/355356557838717")!)
}
else {
// FB not installed
// Do something else
}
I'd anticipate that applications such as Facebook, and others, will implement their Custom URL Schemes in the same manner as their iOS counterparts.

How to open Notification Center via URL Scheme from app?

Using the URL Scheme below, I'm able to open the 'Settings' App from the app I'm currently working on.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
Is it also possible to tweak the URL Scheme so that I can directly open the 'Notification Center' feature inside the 'Settings' App?
Kindly advise. All help appreciated!
I tried this code to prevent crashes from iOS versions and it's working for me:
if ([[UIApplication sharedApplication] respondsToSelector:#selector(openURL:options:completionHandler:)]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:#{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
tested on iOS 8 up;
you can try this url scheme: "prefs:root=NOTIFICATIONS_ID"
But u must add URL types in ur project: Click on ur Project in Project Navigator-> click on TARGET -> tab Info -> and add URL Types by click (+) and add URL scheme : "prefs".
if you still not clear check this Answer here
All the best,

Open a facebook url to the fan page?

I am trying to link our facebook app page to our app, so users can open from our app fan page on Facebook.
I tried :
NSURL *fanPageURL = [NSURL URLWithString:#"fb://profile/APPNAME"];
[[UIApplication sharedApplication] openURL:fanPageURL];
Where app name is the name appears on the url of our facebook fan page.
What happens is that it opens the facebook app at my personal profile and not the relevant page.
Why is that ?
(i dont have any page id to insert to that url )
This code guarantee that if the user don't have the Facebook app, the page will be opened in safari
In this case you have to put your page name and id as follow:
NSURL *fanPageURL = [NSURL URLWithString:#"fb://profile/pageID"];
if (![[UIApplication sharedApplication] canOpenURL:fanPageURL])
fanPageURL = [ NSURL URLWithString:#"https://www.facebook.com/pageName"];
[[UIApplication sharedApplication] openURL:fanPageURL];

iOS, openURL opens odd webpage... (welcome to appe.com)

When user click the link,
it should go to the app store page(angry bird page).
this is the code:
NSString *url = #"http://itunes.apple.com/us/album/angry-birds-rio-samba-single/id426982849?uo=4";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
but, first time when I click the link, it goes to odd webpage.
(blank white page with text "welcome to appe.com", not apple.com).
and when when I click the link again, it goes to the right page.
anyone who experience with this situation?
this is error page on app store.
It's strange. Ia haven't experienced such situation yet. However, the link you are trying to open is not the Angry birds Rio GAME, but a SONG. If you want to lead user to Angry birds Rio game in app store, you should rather use:
NSString* urlString=#"itms-apps://itunes.apple.com/pl/app/angry-birds-rio/id420635506?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
(the protocol is not http:// but itms-apps://
use this link instead
NSString *url = #"http://itunes.apple.com/us/album/angry-birds-rio-samba-single/id426982849?ign-mpt=uo%3D4";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
I double-checked the url. and that was the problem.
I use this url,
http://itunes.apple.com/us/album/angry-birds-rio-samba-single/id426982849
not this correct one,
http://itunes.apple.com/us/album/angry-birds-rio-samba-single/id426982849?uo=4
I modified the url and it fixed the problem.

Launch Facebook page with scheme?

In my app I have a button. Pressing the button takes me to the Facebook app with the scheme: fb://. But I want to have a scheme to link to my facebook page. fb://page/MYPAGENAME doesn't work or am I doing it wrong? Help is much appreciated!
Edit
This is what the method looks like now:
- (IBAction)facebookButton:(id)sender
{
NSURL *url = [NSURL URLWithString:#"fb://MYPAGENAME"];
[[UIApplication sharedApplication] openURL:url];
}
I've added a username to my page now.