Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Settings app from another app programmatically in iPhone

I have to open settings app from my app if gps is not enabled in iPhone. I have used the following code. It works well in iOS simulator but it does not work in iPhone. May I know is there any problem in this code.

if (![CLLocationManager locationServicesEnabled]) {         int (*openApp)(CFStringRef, Boolean);         void *hndl = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices");         openApp = (int(*)(CFStringRef, Boolean)) dlsym(hndl, "SBSLaunchApplicationWithIdentifier");         openApp(CFSTR("com.apple.Preferences"), FALSE);         dlclose(hndl);     } 
like image 657
Edward Sagayaraj Avatar asked Dec 30 '13 12:12

Edward Sagayaraj


People also ask

How do I open app settings in iOS Swift?

To open up the settings in Swift code, first get the URL from the openSettingsURLString property that Apple provides. Then open that URL using the openURL method. To put it on an alert dialog with two options, open settings or dismiss, you could follow this code example.


1 Answers

Good news :

You can open settings apps programmatically like this (works only from iOS8 onwards).

If you are using Swift 3.0:

UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!) 

If you are using Objective-C:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]; 

For other lower versions (less than iOS8) its not possible to programatically open the settings app.

like image 130
Yatheesha Avatar answered Oct 04 '22 20:10

Yatheesha