How to open App in iOS using "appname://openApp?"? - ios

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&param2=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&param2=YYY"]; //fill your params
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}

Related

Link from iOS app to website

I am looking to link my iOS app to my website. I want the link to open the safari web browser. Currently the link goes to the website but stays in the app.
Here is what I am using:
<a onclick="window.location.href='http://www.website.com/folder/page.php';">Contact</a>
Any suggestions?
To open a webpage in device's browse, use following code
NSURL *strURL = [[NSURL alloc] initWithString:#"http://www.website.com/folder/page.php"];
if ([[UIApplication sharedApplication] canOpenURL:strURL]) {
[[UIApplication sharedApplication] openURL:strURL];
} else {
NSLog(#"Cann't open url : %#",strURL);
}

Open AppStore if app is not installed on iOS

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.

Facebook App does not display page when linked from iOS App

I'm working on iOS application. Here is the code i used
NSURL *url = [NSURL URLWithString:#"fb://page/5718758966"];
if ([[UIApplication sharedApplication] canOpenURL:url])
{
[[UIApplication sharedApplication] openURL:url];
}
else
{
//Open the url as usual
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://facebook.com/5718758966"]];
}
As I mentioned, this code has worked to open Facebook app but shows blank page; my question is if there is an alternative link I can use that will both open the app and direct the user to this specific page, or is this simply a Facebook bug?
Thanks!
Instead of "fb://page/5718758966" try "fb://profile/5718758966" for your URL.

Open Facebook url in Safari instead of native app

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

launching SMS app when app starts

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 :)

Resources