iBooks app crashes when opened with IBAction in my app - ios

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.

Related

How to find out how the `Music App` is installed?

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];
}

Launching Safari App without using any specific url from an iOS App

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.

Opening TestFlight app from another app and deep link to specific app

How do i find the scheme of another app and deep link to it from my own iOS app?
More specifically, I want to deep link to the Testflight app upon certain conditions (set by my code). I'm assuming the person has Testflight installed, (which might be a bad assumption but we can live with that assumption).
I know that on Android, you can query for apps and send intents to deep link to someone else's app. What would be the equivalent on iOS?
There are two things you need to do. First, check to see if TestFlight is installed. Then create a new link to your app.
NSURL *customAppURL = [NSURL URLWithString:#"itms-beta://"];
if ([[UIApplication sharedApplication] canOpenURL:customAppURL]) {
// TestFlight is installed
// Special link that includes the app's Apple ID
customAppURL = [NSURL URLWithString:#"https://beta.itunes.apple.com/v1/app/978489855"];
[[UIApplication sharedApplication] openURL:customAppURL];
}
This special https://beta.itunes.apple.com URL will be opened directly in TestFlight.
Finally, if you are using iOS 9 (or later), you need to make an addition to your Info.plist to get the canOpenURL: method to work.
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.
<key>LSApplicationQueriesSchemes</key>
<array>
<string>itms-beta</string>
</array>
From looking at the plist the URL scheme for TestFlight is "itms-beta://" I can't manage to get it deep linking yet, I've tried passing it the Apple ID, with and without a ? along with prefixing it with appleid= I will try bundle ID next.
To open the TestFlight app on the users device you can use:
NSURL *customAppURL = [NSURL URLWithString:#"itms-beta://"];
if ([[UIApplication sharedApplication] canOpenURL:customAppURL]) {
[[UIApplication sharedApplication] openURL:customAppURL];
}
Swift 3/4 answer:
if let customAppURL = URL(string: "itms-beta://"){
if(UIApplication.shared.canOpenURL(customAppURL)){
UIApplication.shared.open(customAppURL, options: [:], completionHandler: nil)
}
}
Most of the built-in applications Apple provides respond to custom URL schemes; for example, the Maps, Mail, YouTube, iTunes, and App Store applications will all open in response to custom URLs. However, there are also many established third-party applications with published URL schemes that you can use in your own application. You can search the applications schemes on
http://handleopenurl.com/
http://wiki.akosma.com/IPhone_URL_Schemes – both have a great list of URL schemes
Once you got the custom URL scheme then you can deep link to that app using the same schema,
NSURL *customAppURL = [NSURL URLWithString:#"urlscheme://"];
//Eg: NSURL *whatsappURL = [NSURL URLWithString:#"whatsapp://send?text=Hello%20World!"];
if ([[UIApplication sharedApplication] canOpenURL:whatsAppURL]) {
[[UIApplication sharedApplication] openURL:whatsAppURL]]];
}
Another way to invoke either one app or another:
- (IBAction)go:(id)sender {
NSString *cnnAppURL = #"cnn://";
NSString *mapsAppURL = #"maps://";
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:cnnAppURL]];
NSString *url = canOpenURL ? cnnAppURL : mapsAppURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
Please read "UseYourLoaf's recent blog post on using URLschemes with canOpenURL. This relates to new security concerns and solutions. Quote:
"This is useful but developers including Twitter and Facebook were using this mechanism to discover the list of Apps installed on a device so they can deliver “tailored content”. Apple decided this is a privacy violation and so in iOS 9 restricted the querying of URL schemes. If you build and link against the iOS 9 SDK you need to whitelist the schemes your app will query. What is important to understand is that this policy can also impact older Apps that have not yet been rebuilt with the iOS 9 SDK."
Please read this link on issues related to the canOpenURL function
Read #picciano's last point - this won't work without modifying your app's plist.

How to open any iOS App from my own App

What I want to do is open any iOS Application (Evernote, safari, Facebook, etc) from my own iOS application. For example, I have created my app with two simple buttons, the first one is named "Evernote" and the second one is named "Safari", so when I click on the "Evernote" button I want that the Evernote App launch on my iOS device, the same when I click on the "Safari" button I want that the button opens my Safari App. How can I do that? It is that possible? If it is, please tell me how. Thank you very much.
yes it possible if you known this app scheme reference URL.
Example call Tel app:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"tel://"]]){
NSString *tell = [#"tel://" stringByAppendingString:phoneNumber];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:tell]];
}
Safari and other is same way.
List common schemes Url here : http://wiki.akosma.com/IPhone_URL_Schemes
Hope this link helps you.
http://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629
If you need to open external apps from your app then follow the above link. Or if you need to open the iOS native apps like phone, mail, safari, etc, you can use URL schemes for opening the app.

Direct link for application updated version in AppStore

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];

Resources