Open Facebook application from my app - ios

Can someone tell the URL schemes to open the Facebook application from my app?

Use fb://.
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 the application is present on the device. If the user has Facebook installed on their device we open it. If the user does not have Facebook installed we open the page through a link, which will launch Safari.
// Check if FB app installed on device
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"fb://profile/355356557838717"]];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"https://www.facebook.com/DanielStormApps"]];
}
Check out iPhone URL Schemes for a list of what else you can achieve via URL Schemes.
Also, starting at iOS 9 you must include LSApplicationQueriesSchemes in your info.plist.

Related

Detecting an app installation on iPhone is failing [duplicate]

This question already has answers here:
iOS 9 not opening Instagram app with URL SCHEME
(14 answers)
Closed 4 years ago.
I am trying to check whether Spotify is installed on iPhone with my code and Spotify is already installed on my device. However its always in else block in code below
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"spotify://"]]) {
//open spotify
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"spotify://"]];
}
else
{
[SVProgressHUD showErrorWithStatus:#"Spotify was not installed"];
[SVProgressHUD dismissWithDelay:1.00];
}
However I can successfully open Spotify with the code below:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"spotify://"]];
I am wondering why canOpenURL is not working for Spotify while it works for Apple Music with music:// URL Scheme.
if ([[UIApplication sharedApplication] canOpenURL:
[NSURL URLWithString:#"spotify://"]])
{
NSLog(#"App Found");
}
else
{
NSLog(#"App Not Found");
}
If your app is linked on or after iOS 9.0, you must declare the URL schemes you want to pass to this method. Do this by adding the LSApplicationQueriesSchemes key to your app's Info.plist file. If you call this method for a scheme not declared using that key, this method always returns false, whether or not an appropriate app is installed. To learn more about the key, see LSApplicationQueriesSchemes.

How does main app know when an sub app has been installed in ios?

How does an app know when an app by the same developer has been installed in iOS?
You can check by openURL method which will help to check app installed in your device or not.
Objective-C:
UIApplication *application = [UIApplication sharedApplication];
NSLog(#"App installed %d",[application canOpenURL:[NSURL URLWithString:#"AppName://"]]);
[application openURL:[NSURL URLWithString:#"AppName://Test"] options:#{} completionHandler:^(BOOL success) {
NSLog(#"Open result %d",success);
}];
Swift:
let appURL = "AppName://extra_param_for_launchscreen"
let URL = NSURL.init(string: appURL)
if UIApplication.sharedApplication().canOpenURL(URL) {
UIApplication.sharedApplication().openURL(URL)
}
by canOpenURL you can check app installed or not.
Note : for iOS 9.0 and grater you need to add
LSApplicationQueriesSchemes in your info.plist file with your app
schema name to white list your app and get installed app status or open app.
Hope this will helps you.
Previously, we can use concept of URL Schemes to find out whether the app we are looking for is installed or not.(By using canOpenURL method). But recently, apple removed this functionality to know whether app installed or not from iOS9 due to privacy policy of apple. So, now you cannot find out the sub app is installed or not in any manner due to security reasons.
Following links might be helpful to you:
canOpenURL to query url schemes
Privacy and URL Schemes in iOS9

Open iOS settings from the app

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
I am using this code to open settings app from my app. But is there any URL to open Background App Refresh settings from my app?
No, you are not able to open any specific part in setting from your app. You are just able to redirect to user to those settings which are related to your app permission.

why can't I open facebook and twitter app with ios 9

Before ios9 comes, I used following code to open facebook app with my app when button clicked.using this if the phone has facebook app, it opens the facebook app and, if it is not, it opens the safari browser.same for the twitter.this is my code.
- (IBAction)facebookButton:(id)sender {
NSURL *facebookUrl = [NSURL URLWithString:#"fb://profile/number"];
if ([[UIApplication sharedApplication] canOpenURL:facebookUrl]) {
[[UIApplication sharedApplication] openURL:facebookUrl];
}
else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.facebook.com/number"]];
}
}
- (IBAction)twitterButton:(id)sender {
NSURL *twitterUrl = [NSURL URLWithString:#"twitter://profile/"];
if ([[UIApplication sharedApplication] canOpenURL:twitterUrl]) {
[[UIApplication sharedApplication] openURL:twitterUrl];
}
else{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.twitter.com/"]];
}
}
this worked fine, before iOS 9.but now if app exists or not, it only opens with safari.help me with this
we have to add followings in info.plist
From Apple documentation on canOpenURL: method:
If your app is linked on or after iOS 9.0, you must declare the URL
schemes you want to pass to this method. Do this by using the
LSApplicationQueriesSchemes array in your Xcode project’s Info.plist
file. For each URL scheme you want your app to use with this method,
add it as a string in this array.
If your (iOS 9.0 or later) app calls this method using a scheme you
have not declared, the method returns NO, whether or not an
appropriate app for the scheme is installed on the device.
Unlike this method, the openURL: method is not constrained by the
LSApplicationQueriesSchemes requirement: If an app that handles a
scheme is installed on the device, the openURL: method works, whether
or not you have declared the scheme.
Apple add this change to API, because canOpenURL: method was often used to receive information about applications, installed on user device, without actual openURL: calls.
Issue can be resolved in the following ways:
Add "fb" and "twitter" URL schemes into LSApplicationQueriesSchemes array in your Info.plist;
openURL: method returns NO if URL wasn't successfully opened. You can rewrite code in following way to avoid canOpenURL: call:
if (![[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"fb://profile/number"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.facebook.com/number"]];
}
Look into Universal Links, that works in similar way - open application, if it is available on device, otherwise URL is opened in Safari.
Custom deep linking schemas does not work on iOS9 anymore. You need to use Universal Links. See this guide.

Launching settings app from custom iOS application

Is there any way to launch the build-in iOS settings application from our custom applications.
Based on the URL schema , it is possible to launch safari,maps,YouTube,iTunes... etc. But in the documentation there is no any info related with settings app.
TIA.
-Balaji R.
//code for opening settings app in iOS 8
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
//code for opening settings App in ios5
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=WIFI"]];
No you can not. Opening the Settings app from another app

Resources