Call the official *Settings* app from my app on iPhone - iphone

At one point in my app, I would like to redirect the user to the official Settings app. If possible, I also want go straight to the Network section within the Settings app.
I think what I need is the Settings app's url scheme and the format to construct my request. But I doubt that calling such an official app is forbidden.
Can anyone can help me?

As noted in the comments below, this is no longer possible in iOS version 5.1 and after.
If you are on iOS 5.0, the following applies:
This is now possible in iOS 5 using the 'prefs:' url scheme. It works from a web page or from an app.
example urls:
prefs:root=General
prefs:root=General&path=Network
sample usage:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=General"]]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=General&path=Network"]]

From IOS 8 you can call the settings from within app with this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

It's also work in iOS version > 5.1, but you must add an URL schemes in URL types in Xcode:
Then you can use
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=WIFI"]];
It's can open system WiFi setting
now.
Other path please find in this answer: iOS Launching Settings -> Restrictions URL Scheme.

Bad news: As #Hlung and #jasongregori suggested, for iDevices whose OS version >= iOS 5.1 && < iOS 8.0, there is once again NO official/documented way to call the built-in Settings app from a third-party app. Period.

Calling the settings app from other app is possible only from iOS 8. So, use the following code
if([CLLocationManager locationServicesEnabled]&&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
//...Location service is enabled
}
else
{
if([[[UIDevice currentDevice] systemVersion] floatValue]<8.0)
{
UIAlertView* curr1=[[UIAlertView alloc] initWithTitle:#"This app does not have access to Location service" message:#"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[curr1 show];
}
else
{
UIAlertView* curr2=[[UIAlertView alloc] initWithTitle:#"This app does not have access to Location service" message:#"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Settings", nil];
curr2.tag=121;
[curr2 show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 121 && buttonIndex == 1)
{
//code for opening settings app in iOS 8
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}

from iOS 8, you can redirect with
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
enjoy coding

Just an additional answer to add onto the one's addressing iOS8+. If you're supporting anything below 8, you should check to see if it's supported
BOOL canGoToSettings = (UIApplicationOpenSettingsURLString != NULL);
if (canGoToSettings)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}

For settings in iOS 9 this is worked for me.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=Settings"]];
But make sure you add a url schemes in URL types in
Info tab in app targets.

For iOS 10 you can use:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"App-Prefs:root=Settings"]];
It is also working on iOS 9!

Related

How to launch another app from an iPhone app

I am working on a map application in my iPhone app.
I have a button go.
When the user clicks this button in this method I want to check if user has installed the waze application on his iphone. If yes then navigate to waze application otherwise open iPhone's default map app.
Try to do this way :
NSString *wazeAppURL = #"waze://";
NSString *mapsAppURL = #"maps://";
BOOL canOpenURL = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:wazeAppURL]];
NSString *url = canOpenURL ? wazeAppURL : mapsAppURL;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
Here, canOpenURL allows you to test if the Waze app is installed on your iPhone. if iPhone can open the url waze:// it means you already have the app and it will launch it. Otherwise it will launch the default Maps app. Safari won't be called.
To open an app you need to call
BOOL canOpenURL = [[UIApplication sharedApplication]
canOpenURL:[NSURL URLWithString:#"app://"]];
if ( canOpenUrl ) [[UIApplication sharedApplication]
openURL:[NSURL URLWithString:url]];
To find all the url, go to this page: http://handleopenurl.com/
For waze in particular, http://handleopenurl.com/scheme/waze
hope this helps.
Note that on iOS you can also navigate to Google Maps -- and pass along the query string or geopoint. Here's one example of navigating to a specific geopoint:
if (self.mapView.userLocation.location) {
NSString *urlAsString = [NSString stringWithFormat:#"comgooglemaps://?q=%f,%f", self.mapView.userLocation.location.coordinate.latitude, self.mapView.userLocation.location.coordinate.longitude];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlAsString]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlAsString]];
}
}
Just a suggestion to enhance the user experience.

Open Twitter settings from app in iOS 5.1

I am implementing Twitter in my iPhone application and if the user does not have any Twitter accounts set up, I would like him to be able to open his Twitter settings from my app. Is there any way to do this in iOS 5.1?
In iOS 5.0 we could do as below but I have not managed to find a way to do this in 5.1
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=TWITTER"]];
Try this..
TWTweetComposeViewController *ctrl = [[TWTweetComposeViewController alloc] init];
if ([ctrl respondsToSelector:#selector(alertView:clickedButtonAtIndex:)]) {
// Manually invoke the alert view button handler
[(id <UIAlertViewDelegate>)ctrl alertView:nil
clickedButtonAtIndex:0];
}
[ctrl release];
I don't know the reason why but Apple has removed the settings apps URL Schemes. Yes it was working in iOS 5.0 but it doesn't work in 5.1

Make calls from iPhone app [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
make a call in iphone from my application
I want to make a phone call on given number from my iPhone application. Could you suggest any good tutorial which explains it the best or tell me the process?
You can try :
NSURL *phoneNumberURL = [NSURL URLWithString:#"tel:80001212"];
[[UIApplication sharedApplication] openURL:phoneNumberURL];
NSString* phoneNumber=TextFiled Name
NSString *number = [NSString stringWithFormat:#"%#",phoneNumber];
NSURL* callUrl=[NSURL URLWithString:[NSString stringWithFormat:#"tel:%#",number]];
//check Call Function available only in iphone
if([[UIApplication sharedApplication] canOpenURL:callUrl])
{
[[UIApplication sharedApplication] openURL:callUrl];
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"ALERT" message:#"This function is only available on the iPhone" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
Try this:-
NSString *phoneNumber = #"15555551212";
NSString *dtmfAfterPickup = #"1234";
NSString *telString = [NSString stringWithFormat:#"tel:%#,%#", phoneNumber, dtmfAfterPickup];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:telString]];
Opening an app from within another app is managed in iOS through the "url scheme" mechanism. If an app defines an url scheme, and this scheme is public, you can then use it to run that app.
Basic rule is to first check that your device supports that scheme (e.g. you cannot make a phone call on an iPad because the phone app is not installed) and then, if the answer is positive, call it:
if([[UIApplication sharedApplication] canOpenURL:myURL]) {
[[UIApplication sharedApplication] openURL:myURL];
} else {
// do something else, e.g. inform the user that he/she cannot open the app
}
This check is important as for some schemes, e.g. the phone one, the system checks is the url is well formed or not. E.g.: for phone numbers space between digits is not supported.
The most common Apple URL schemes are described here:
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html#//apple_ref/doc/uid/TP40007893-SW1
In particular, the telephone url scheme is here:
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/PhoneLinks.html#//apple_ref/doc/uid/TP40007893-SW1
Finally there is a web site, called handleOpenURL that is trying to collect all apps url schemes. If you define an app that exposes an url scheme and you want it to be public, don't hesitate to post it in this site.
There are two ways to acheive this:-
1) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://9912345678"]];
2) You can use the UITextView and enable phone detection. After that the phone number will look like hyperlinked. Use the following code.
mytextview.text = #"9943586256";
mytextview.dataDetectorTypes = UIDataDetectorTypePhoneNumber;
mytextview.editable=NO;
Helpful if you want to show the phone number inside a custom tableview cell.
I would personally like the second one due to requirements in some project. When i have give the telephone number in UITextView and upon pressing that will start the calling.

How to return to my iphone application after call ends?

I am able to call from my iphone application by using below code:
NSString *phoneNumber = #"tel://1234567890";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Now, i want to know how to return to my application back when the call ends ?
UIWebView *phoneCallWebview = [[UIWebView alloc] init];
// [self.view addSubview:phoneCallWebview];
NSURL *callURL = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", 9238928399]];
[phoneCallWebview loadRequest:[NSURLRequest requestWithURL:callURL ]];
As far as I'm aware, such interaction is impossible since your application has been demoted to background, and all UI interaction has been delegated to the Phone app, and the user.
I found this SO question
End call, don't return to app automatic in iphone 3.1 version
Which pointed to an article on apple dev forums
https://devforums.apple.com/message/128046 (dev account required)
Which says it was a change in iOS 3.1 but a "workaround" is
use UIWebView to open the tel: url, after the call, your app will relaunch, but you get the annoying do you want to make this call alert.
I have't verified this works as described, just thought I'd point it out
From iOS 5, use below...
NSString *phoneNumber = [#"telprompt://" stringByAppendingString:#"12345678"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]];
Just use telprompt:// instead of tel://
telprompt will prompt the user first, and when call ends,it will go back to your application.
NSString *myNumber = [#"telprompt://" stringByAppendingString:txtMobileNo.titleLabel.text];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:myNumber]];

Detecting programmatically whether an app is installed on iPhone

I am in this situation where I have to display a button which says "Open myApp" (if myApp is installed on the device) or it says "Download myApp" (if myApp is not installed on the device) in an iphone app. To do this, I need to detect whether an app (with a known custom URL) has been installed on the device. How can I do this? Thanks in advance.
UPDATED 8th January 2014 - 3 things you can do
I actually had to do this for a client again. They wanted users to be able to open their second app from the main app if it had been installed.
This is my finding. Use the canOpenURL method to check if an app is installed or/and then use the openURL method to
Open the application installed on the iOS device
Take the user to the app store directly pointing them to the app/your list of developer apps
Take them to a website instead
All code samples available for each scenario
//Find out if the application has been installed on the iOS device
- (BOOL)isMyAppInstalled {
return [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"nameOfMyApp:"]];
}
- (IBAction)openOrDownloadApp {
//This will return true if the app is installed on the iOS device
if ([self myAppIsInstalled]){
//Opens the application
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"nameOfMyApp:"]];
}
else { //App is not installed so do one of following:
//1. Take the user to the apple store so they can download the app
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://itunes.com/apps/nameOfMyApp"]];
//OR
//2. Take the user to a list of applications from a developer
//or company exclude all punctuation and space characters.
//for example 'Pavan's Apps'
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itms://itunes.com/apps/PavansApps"]];
//OR
//3. Take your users to a website instead, with maybe instructions/information
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.pavan.com/WhyTheHellDidTheAppNotOpen_what_now.html"]];
}
}
Choose one option, I've just spoiled you with choice. Choose one that fits your requirements.
In my case I had to use all three options in different areas of the program.
If the URL scheme for your app is "myapp:", then
BOOL myAppInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"myapp:"]];
(Requires iOS 3.0.)
To check app is install in device or not
1) In info.plist add LSApplicationQueriesSchemes as below example
2) and in URL Types
3) Now to check app is install or not
- (IBAction)openAppPressed:(UIButton *)sender {
NSString *urlString = #"XYZAPP://";
NSURL *url = [NSURL URLWithString:urlString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"itunes link for download app"]];
}
}
You can add a simple meta tag in the head of any page that needs this app-sniffing.
For more info, go here:
http://developer.apple.com/library/ios/#documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html
For those using canOpenURL it is always safe to migrate from this to openURL:options:completionHandler:
NSString *urlString = #"XYZAPP://";
NSURL *url = [NSURL URLWithString:urlString];
[[UIApplication sharedApplication] openURL:url options:#{} completionHandler:^(BOOL success) {
if (!success) {
[[UIApplication sharedApplication] openURL:appStoreUrl options:#{} completionHandler:nil];
}
}];
because that doesn't require you to declare the scheme ahead of time.
canOpenURL which is deprecated already has some odd limitations because Twitter used it to detect hundreds of apps long ago.