Link to iTunes have to restart app - objective-c

Im Linking to appstore from my app using
 
`NSString *iTunesLink = #"itms-apps://itunes.com/apps/companyname/";
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
This works, but when returning to my app it's just a blank screen and I have to restart the app.
Am I missing some fundemanatal piece of code here

Try using a link with this format itms-apps://ax.itunes.apple.com/app/id123456789

Related

Open settings programmatically in iOS

I am opening the device settings page from my app.When I open through iPhone X(iOS11) and iPhone 8 it goes to app settings . But when I open through iPhone 8 Plus and iPhone SE it goes to home settings page.
I need to open home settings page of iPhone like iPhone 8 Plus(open home settings page) . I am running the below code.
UIApplication *application = [UIApplication sharedApplication];
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[application openURL:settingsURL options:#{} completionHandler:^(BOOL success) {
if (success) {
NSLog(#"Opened url");
}
}];
My problem is, I created a new project and I ran this above code . Its working fine.And I can able to navigate to device home settings page in same iPhone X.
But when I run this code in my project in iPhone X it goes to app settings screen.I don't know where I missed.
Please help me if possible.
Thanks in advance.
Global Variable
UIApplicationOpenSettingsURLString
Used to create a URL that you can pass to the openURL: method. When you open the URL built from this string, the system launches the Settings app and displays the app’s custom settings, if it has any.
https://developer.apple.com/documentation/uikit/uiapplicationopensettingsurlstring?language=objc
This is from Apple official document. My guess is your app have its own setting page, that's why openURL function takes you to app's setting page instead of Setting home.

How do I open another application with tvOS?

Does UIApplication:openURL work?
NSString *iTunesLink = #"http://www.youtube.com/watch?v=TFFkK2SmPg4";
BOOL did = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
This does nothing.
I assume you're wanting to test a Custom URL Scheme. You will want to use canOpenURL to see if the URL can be opened first. 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 you would continue to open the URL with openURL.
YouTube links open the YouTube app by default on iOS devices. This behavior is not yet testable on the new Apple TV as YouTube's app is not accessible in the tvOS beta.
Here's an example of how to use canOpenURL to see if Facebook is installed on an iOS device using its Custom URL Scheme:
Obj-C:
// Check if FB app installed on device
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"fb://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"fb://profile/355356557838717"]];
}
else {
// FB not installed
// Do something else
}
Swift:
// Check if FB app installed on device
if UIApplication.sharedApplication().canOpenURL(NSURL(string:"fb://")!) {
UIApplication.sharedApplication().openURL(NSURL(string:"fb://profile/355356557838717")!)
}
else {
// FB not installed
// Do something else
}
I'd anticipate that applications such as Facebook, and others, will implement their Custom URL Schemes in the same manner as their iOS counterparts.

How to open Notification Center via URL Scheme from app?

Using the URL Scheme below, I'm able to open the 'Settings' App from the app I'm currently working on.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
Is it also possible to tweak the URL Scheme so that I can directly open the 'Notification Center' feature inside the 'Settings' App?
Kindly advise. All help appreciated!
I tried this code to prevent crashes from iOS versions and it's working for me:
if ([[UIApplication sharedApplication] respondsToSelector:#selector(openURL:options:completionHandler:)]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:#{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
tested on iOS 8 up;
you can try this url scheme: "prefs:root=NOTIFICATIONS_ID"
But u must add URL types in ur project: Click on ur Project in Project Navigator-> click on TARGET -> tab Info -> and add URL Types by click (+) and add URL scheme : "prefs".
if you still not clear check this Answer here
All the best,

I can't open Mail app?

I'm trying to open iOS's mail application by clicking a button.
So I did this :
NSString *mailString = [NSString stringWithFormat:#"mailto://test#test.com"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
But nothing in particular happens... what's the problem ?
Thanks for your advices
#"mailto:test#test.com"
instead of
#"mailto://test#test.com"
Better way of doing this would be to use MFMailComposeViewController
And it works only on the real device, not on the simulator (in my case)

Url scheme : Open app or Appstore from mail

I'm creating an application where users can share data by sending emails to each other.
In this mail there is a link to my app (I created an URL scheme for my app)
But, if the users doesn't have my application on his iPhone, then when he clicks on the link, nothing happens.
My question : How could I do to launch my app when the application is installed on the user's iPhone and launch the Appstore or a website if this application is not installed
Thank you
canOpenURL is what you're looking for.
Here is an example for launching twitter app:
NSURL* twitterURL = [NSURL URLWithString:[NSString stringWithFormat:#"twitter:#%#", twitterUser]];
if ([[UIApplication sharedApplication] canOpenURL:twitterURL]) {
[[UIApplication sharedApplication] openURL:twitterURL];
} else {
NSURL* url = [NSURL URLWithString:#"http://itunes.apple.com/us/app/twitter/id333903271?mt=8"];
[[UIApplication sharedApplication] openURL:url];
}
EDIT
If you want do do this from a webpage or html email, you find your answer here:
https://stackoverflow.com/a/627942/550177
and here:
https://stackoverflow.com/a/1109200/550177