0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
birdcage
  • 2,638
  • 4
  • 35
  • 58

1 Answers1

1
  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.

9to5ios
  • 5,319
  • 2
  • 37
  • 65