My app imports music from the Music app via MPMediaPickerController. A modal will appear even if the user has deleted the music app. However, if it was deleted in iOS13, the modal no longer appears. So I want to check if the Music app is installed. I tried the following code and confirmed that YES is returned even if it is not installed.
- (BOOL)isInstalledMusicApp
{
NSURL *url = [NSURL URLWithString:#"music://"];
return [[UIApplication sharedApplication] canOpenURL: url];
}
Related
In one of my iOS App, I have to just launch the Safari App and not open some specific Url in Safari which can be achieved by this:
NSURL *url = [NSURL URLWithString:#"http://www.stackoverflow.com"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(#"%#%#",#"Failed to open url:",[url description]);
}
But I only need to launch safari App with last tab open (in the same state that I leave before entering that iOS App).
Any suggestion and help will be welcome.
Thanks!
Actually we can open a specific app from safari. You have to create a custom url scheme for the application and open that link from safari like any other link is opened from safari.
Create a custom url scheme like
myApp://
Then open it from safari e.g on onClick of button.
Objective C
NSURL *url = [NSURL URLWithString:#"http://about:blank"];
if (![[UIApplication sharedApplication] openURL:url]) {
NSLog(#"%#%#",#"Failed to open url:",[url description]);
}
Swift 3.0
UIApplication.shared().openURL(URL(string: "http://about:blank")!)
Hope It will help you.
Add Comment if you require any other information.
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.
All right, I am having a problem opening the iBooks app using an IBAction in my app. I have it set up so that when the user presses a button, it calls this action to open the iBooks app:
-(IBAction)openBooks:(id)sender
{
NSString *stringURL = "iBooks://";
NSURL *url = [NSURL URLWithString:stringURL];
[[UIApllication sharedApplication] openURL:url];
}
This does the whole app switching this and looks great. I see the bookshelf where all of my books should be, but then the iBooks app crashes before my books load! The app I wrote doesn't crash, but iBooks fails!
I am running my app via XCode (the app isn't actually distributed to my iPad, per se), is that why iBooks crashes? When I touch the iBooks icon to open it (not via my app) it opens fine and works. But if I change the url in my IBAction like this:
NSString *stringURL = "maps://";
and run my app, my button works and Maps opens up!
Is this an iBook bug? Or is it my bug?
FWIW, I'm using iOS 6 and XCode 4.6.3
You HAVE to check if iOS can open a url before opening it. Either your url scheme is wrong (like in your case) or the user doesn't even have iBooks installed. Even if you have the correct url you can't open it unless the user has installed an app that corresponds to the url.
NSURL *url = ...
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
else {
// can't open url
}
OK, so my bad. I found that I was using the wrong URL scheme. The iBooks:// I got from wiki.akosma does NOT work, but itms-books: DOES work.
I'm developing an app for iOS 6 with Facebook Share option. I need to check out that this app can able to check wether Facebook app was installed in device or not.
I have already tried with Account Store. But it was not working. Is there any some other way for this issue. I need help with code. Thanks in advance
You can test for it using -[UIApplication canOpenURL:]. The facebook custom URL scheme is "fb:".
NSURL *url = [NSURL URLWithString:#"fb://profile"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
// Facebook is installed
}
Within my application there is alink to to appstore for downloading the new version of my application.
When user press this link, the iPhone open some screes before getting the AppStore screen.
Those screen, seem to be the browser's screens, but i'm not sure.
How can i create a direct link to my application in AppStore?
Thanks,
Eyal.
itms-apps://itunes.com/apps/APPNAME
Example:
NSURL *url = [NSURL URLWithString:#"itms-apps://itunes.com/apps/trenes"];
[[UIApplication sharedApplication] openURL:url];