Using Settings.app URL scheme

Hi all!

We're going to let users launch Settings.app from our application, so is it possible to add URL scheme "prefs" to our application URL types?

Is it private API or not? Will we get rejected in AppStore review for using that?


let url = NSURL(string: "prefs:root=Settings")
UIApplication.sharedApplication().openURL(url!)

Accepted Reply

You should use the UIApplicationOpenSettingsURLString to create an NSURL that will open the settings page for your app.

Replies

Have you actually tried that URL scheme on the most recent versions of iOS, or are you dealing with second hand documentation?

We've already tried this feature on ios 8+ and it works perfeclty. But we haven't found any official docs about it and we're not sure it's allowed to use.

You should use the UIApplicationOpenSettingsURLString to create an NSURL that will open the settings page for your app.

Thank you for your answer.


We know about that, but we want to open general settings instead of apllication settings.

UIApplicationOpenSettingsURLString works fine if app doesn't have any settings. But we can't get why every application has at least "Location" setting even if it doesn't have Settings bundle in its project.

I'm not a Core Location expert but it is my understanding that your app receives the Location option under its Settings entry because it has, at some point, called one of the location APIs. This was added in iOS 8 - previously the location settings for all apps could only be configured from the Privacy settings.

We know about that, but we want to open general settings instead of apllication settings.

I'm afraid that there is not a documented URL scheme to do that. You should describe your use case in an enhancement request so that such a URL scheme can be considered for inclusion in a future version of the iOS SDK.

We have been facing issues with UIApplicationOpenSettingsURLString in iOS 10. Settings app seems to crash on fresh install by using above string.


Below is crash report for the same :


Process: Preferences [5389]

Path: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/Applications/Preferences.app/Preferences

Identifier: Preferences

Version: 1 (1.0)

Code Type: X86-64 (Native)

Parent Process: launchd_sim [5302]

Responsible: Preferences [5389]

User ID: 501


Date/Time: 2016-12-13 15:42:39.413 -0800

OS Version: Mac OS X 10.12.1 (16B2555)

Report Version: 12

Anonymous UUID: 76E9BE6A-ACFC-5C32-D0AC-D0534FCE4A40


Sleep/Wake UUID: 06CAF827-9781-41E2-AD07-B7E6EF075396


Time Awake Since Boot: 19000 seconds

Time Since Wake: 9600 seconds


System Integrity Protection: enabled


Crashed Thread: 0 Dispatch queue: com.apple.main-thread


Exception Type: EXC_CRASH (SIGABRT)

Exception Codes: 0x0000000000000000, 0x0000000000000000

Exception Note: EXC_CORPSE_NOTIFY


Application Specific Information:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSBundle initWithURL:]: nil URL argument'

terminating with uncaught exception of type NSException

abort() called

CoreSimulator 338.16 - Device: iPad Air 2 - Runtime: iOS 10.2 (14C89) - DeviceType: iPad Air 2



Application Specific Backtrace 1:

0 CoreFoundation 0x0000000108738d4b __exceptionPreprocess + 171

1 libobjc.A.dylib 0x0000000108b3a21e objc_exception_throw + 48

2 CoreFoundation 0x00000001087a22b5 +[NSException raise:format:] + 197

3 Foundation 0x000000010bd0221d -[NSBundle initWithURL:] + 87

4 Foundation 0x000000010bd021b3 +[NSBundle bundleWithURL:] + 45

5 PreferencesUI 0x000000010902263b -[PSUIPrefsListController _reallyLoadThirdPartySpecifiersForApps:withCompletion:] + 821

6 PreferencesUI 0x00000001090221e2 -[PSUIPrefsListController loadThirdPartySpecifierIfNeededForBundleID:] + 452

7 Preferences 0x00000001085bd17d Preferences + 37245

8 Preferences 0x00000001085ba9b5 Preferences + 27061

9 UIKit 0x000000010cdb9898 __45-[UIApplication _applicationOpenURL:payload:]_block_invoke + 1005

10 UIKit 0x000000010cdb91e6 -[UIApplication _applicationOpenURL:payload:] + 757

11 UIKit 0x000000010cda70cc -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 5137

12 UIKit 0x000000010cdad0ed -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731

13 UIKit 0x000000010cdaa26d -[UIApplication workspaceDidEndTransaction:] + 188

14 FrontBoardServices 0x000000010911f6cb __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24

15 FrontBoardServices 0x000000010911f544 -[FBSSerialQueue _performNext] + 189

16 FrontBoardServices 0x000000010911f8cd -[FBSSerialQueue _performNextFromRunLoopSource] + 45

17 CoreFoundation 0x00000001086dd761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17

18 CoreFoundation 0x00000001086c298c __CFRunLoopDoSources0 + 556

19 CoreFoundation 0x00000001086c1e76 __CFRunLoopRun + 918

20 CoreFoundation 0x00000001086c1884 CFRunLoopRunSpecific + 420

21 UIKit 0x000000010cda8aea -[UIApplication _run] + 434

22 UIKit 0x000000010cdaec68 UIApplicationMain + 159

23 Preferences 0x00000001085b694f Preferences + 10575

24 libdyld.dylib 0x000000010f09368d start + 1



Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

0 libsystem_kernel.dylib 0x000000010f3bcdda __pthread_kill + 10

1 libsystem_pthread.dylib 0x000000010f3f4787 pthread_kill + 90

2 libsystem_c.dylib 0x000000010f136fd7 abort + 129

3 libc++abi.dylib 0x000000010ef0f95a abort_message + 266

4 libc++abi.dylib 0x000000010ef34cff default_terminate_handler() + 267

5 libobjc.A.dylib 0x0000000108b3a49f _objc_terminate() + 103

6 libc++abi.dylib 0x000000010ef31e69 std::__terminate(void (*)()) + 8

7 libc++abi.dylib 0x000000010ef31af4 __cxa_rethrow + 99

8 libobjc.A.dylib 0x0000000108b3a3b7 objc_exception_rethrow + 40

9 com.apple.CoreFoundation 0x00000001086c190b CFRunLoopRunSpecific + 555

10 com.apple.UIKit 0x000000010cda8aea -[UIApplication _run] + 434

11 com.apple.UIKit 0x000000010cdaec68 UIApplicationMain + 159

12 com.apple.Preferences 0x00000001085b694f 0x1085b4000 + 10575

13 libdyld.dylib 0x000000010f09368d start + 1

This also came up in https://forums.developer.apple.com/thread/63425. As I requested in that thread, if people are seeing this crash you should write a bug so we can see what's going on. Ideally with a small test app that exhibits the behavior, or at the least a version of your app .ipa or xcode archive where you're seeing it. Please post your bug number in that other thread.