I would like to open Appstore if app is not installed on iPhone. E.g. I want to open facebook from my app. I'm doing it like that
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *ourPath = #"fb://profile/1234";
NSURL *ourURL = [NSURL URLWithString:ourPath];
[ourApplication openURL:ourURL];
But if facebook app is not installed on device I get such error:
LaunchServices: ERROR: There is no registered handler for URL scheme fb
in such case I would like to take user to facebook app on AppStore. I know I can do it like that:
NSString *stringURL = #"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=294409923&mt=8";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
but how I will know what is Facebook AppStore id?
Check the return value of openURL:. If it returns NO, then create a SKStoreProductViewController setup for the desired app.
if (![ourApplication openURL:ourURL]) {
// can't launch app for 'fb' scheme
// Create and display SKStoreProductViewController
}
If you don't want to use SKStoreProductViewController then use the openURL code you have at the end of your question instead.
Related
After iOS 13 update the url scheme for reminders app x-apple-reminder:// does not work anymore.
NSString *url = #"x-apple-reminder://";
NSURL *URL = [NSURL URLWithString:url];
[[UIApplication sharedApplication] openURL:URL];
How can I find the new url scheme? I searched on the web,but I could not find anything.
The new url for the reminders app in iOS13 is x-apple-reminderkit://.
Can I know the code for facebook application? for example https://www.facebook.com/nike/?fref=ts .. I tried it bit it didn't work. I tried it with the youtube code but it didn't work!
For example for youtube
-(IBAction)btnYoutube:(id)sender {
NSURL *linkToAppURL = [NSURL URLWithString:[NSString stringWithFormat:#"youtube://user/%#",#"toyotaleasing"]];
NSURL *linkToWebURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.youtube.com/user/%#",#"toyotaleasing"]];
if ([[UIApplication sharedApplication] canOpenURL:linkToAppURL]) {
// Can open the youtube app URL so launch the youTube app with this URL
[[UIApplication sharedApplication] openURL:linkToAppURL];
}
else{
// Can't open the youtube app URL so launch Safari instead
[[UIApplication sharedApplication] openURL:linkToWebURL];
}
}
Does anyone know?
If you see the log in console it will show below log :
-canOpenURL: failed for URL: "youtube://user/toyotaleasing" - error: "This app is not allowed to query for scheme youtube"
The solution is, you need to "whitelist" all your URL schemes which will be used in your app, list down in info.plist.
info.plist key for this is "LSApplicationQueriesSchemes".
This is how your info.plist look like when you add "youtube" as scheme.
Now it will work.
I need to open another app with parameters from my iOS App.
I have specific URL scheme provided from the developers of the App that have to be opened:
secondApp://openApp?param1=XXX¶m2=YYY
I try to search Google how to open App in this way but I did not found any example how to use this construct.
Can you provide me with link or a row of code how to open App in this way?
You can look into this documentation of Inter-App Communication provided by Apple. Also, you can look into this tutorial. Here, they are sending text to another app. Also, another detailed answer to your question can be found in here.
Following code from the tutorial will help you :
-(IBAction) openReceiverApp {
// Opens the Receiver app if installed, otherwise displays an error
UIApplication *ourApplication = [UIApplication sharedApplication];
NSString *ourPath = #"secondApp://openApp?param1=XXX";
NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL]) {
[ourApplication openURL:ourURL];
}
}
To open second app from your iOS app, just use:
NSURL *url = [NSURL URLWithString:#"secondApp://openApp?param1=XXX¶m2=YYY"]; //fill your params
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
is there any way to open Facebook url (ex. http://www.facebook.com/facebook) in Safari instead of native app? I'm tried to do this:
NSURL *url = [NSURL URLWithString:#"http://www.facebook.com/facebook"];
[[UIApplication sharedApplication] openURL:url];
but iOS automatically launch native client (of course if it's installed) if you try to open url with in facebook domain. thanks.
Ok, I think I found answer, you must replace "www.facebook.com" with "facebook.com" in url.
Something like this:
NSString *facebookUrlString = #"http://www.facebook.com/facebook";
if ([[facebookUrlString pathComponents] count] > 0) {
if ([[facebookUrlString pathComponents][1] isEqualToString:#"www.facebook.com"]) {
NSMutableArray *pathComponents = [[facebookUrlString pathComponents] mutableCopy];
[pathComponents replaceObjectAtIndex:1 withObject:#"facebook.com"];
facebookUrlString = [NSString pathWithComponents:pathComponents];
}
}
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:facebookUrlString]];
Copy link to the messenger app and send to yourself. Open the link on messenger app and click on share and will apear open with facebook app
I need to open the pre installed SMS app in iPhone.
I know how to open SMS app using MFMessageUI class, but the problem is that it can be used to display it as a modal view which in turns requires a view controller.
Does anybody know how to populate it in AppDelegate didFinishLaunchingWithOptions?
Try this code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"sms:1234567890"]];
NSString *stringURL = #"sms:+12345678901";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApplication sharedApplication] openURL:url];
This :)