Detecting an app installation on iPhone is failing [duplicate] - ios

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.

Related

Url Scheme for ADVERTISING iOS 12.0

I used:
NSURL *url = [NSURL URLWithString:#"App-Prefs:root=Privacy&path=ADVERTISING"];
[[UIApplication sharedApplication] openURL:url];
it worked on iOS 11.x and before.
but with iOS 12.x it doesn't work.
Apple no longer allows prefs:root= via section 2.5.1 in their guidelines (they now consider what you're doing a non-public URL scheme).
The best you can do is open up your app settings and the top level should be simple enough that the user can get to where they need from there.
Perhaps something like:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

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.

Open setting from Application iOS9 [duplicate]

This question already has answers here:
is it possible to open Settings App using openURL?
(4 answers)
Closed 7 years ago.
I am trying to open setting from my app in a button action, I know the following code works but how can I do similar thing on iOS 9?
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:#"General&path=Network/VPN"]];
Or is there any other way to open setting page from app?
If it is not possible can I open Wifi setting?
Found the solution:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=Safari"]];
You can do like this to open settings page from your app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

Open Facebook application from my app

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.

How to detect if Facebook app is installed on iOS? [duplicate]

This question already has answers here:
How to check programmatically if an App is installed?
(6 answers)
How can I determine if a user has an iOS app installed?
(4 answers)
Closed 9 years ago.
On iOS, you can launch the Facebook app and link to a profile by opening a url like this: fb://profile/12345
The only problem is that if the Facebook app isn't installed, nothing happens.
Is there a way to detect if the app is installed or if the url scheme fb:// is supported?
This would apply broadly to other apps like Twitter as well.
BOOL isInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]]
if (isInstalled) {
} else {
}
Try just using the canOpenURL: function
NSURL *fbURL = [NSURL URLWithString:#"fb://"];//or whatever url you're checking
if ([[UIApplication sharedApplication] canOpenURL:fbURL])
{
//open it etc
}

Resources