Okay, I know that there are many question about it, but they are all from many time ago.
So. I know that it is possible because the Map app does it.
In the M
In Swift 3 all I needed is this (here for example redirect to my app notifications):
if let url = URL(string: "App-Prefs:root=NOTIFICATIONS_ID&path=your app bundleID") {
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, completionHandler: .none)
} else {
// Fallback on earlier versions
}
}
Source: phynet gist.
This worked with me only when settings is in background. It will redirect you to your app notification settings but if settings wasn't running in the background it will just redirect you to notification settings in general.
Add this to your class,
public class func showSettingsAlert(title:String,message:String,onVC viewController:UIViewController,onCancel:(()->())?){
YourClass.show2ButtonsAlert(onVC: viewController, title: title, message: message, button1Title: "Settings", button2Title: "Cancel", onButton1Click: {
if let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString){
UIApplication.sharedApplication().openURL(settingsURL)
}
}, onButton2Click: {
onCancel?()
})
}
public class func show2ButtonsAlert(onVC viewController:UIViewController,title:String,message:String,button1Title:String,button2Title:String,onButton1Click:(()->())?,onButton2Click:(()->())?){
dispatch_async(dispatch_get_main_queue()) {
let alert : UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: button1Title, style:.Default, handler: { (action:UIAlertAction) in
onButton1Click?()
}))
alert.addAction(UIAlertAction(title: button2Title, style:.Default, handler: { (action:UIAlertAction) in
onButton2Click?()
}))
viewController.presentViewController(alert, animated: true, completion: nil)
}
}
Call like this,
YourClass.showSettingsAlert("App would like to access camera", message: "App would like to access camera desc", onVC: fromViewController, onCancel: {
print("canceled")
})
You can use this on iOS 5.0 and later: This no longer works.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
Swift 3:
guard let url = URL(string: UIApplicationOpenSettingsURLString) else {return}
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
// Fallback on earlier versions
UIApplication.shared.openURL(url)
}
Swift 4
I prefer to open setting in a safer way,
if let settingUrl = URL(string:UIApplicationOpenSettingsURLString) {
UIApplication.shared.open(settingUrl)
}
else {
print("Setting URL invalid")
}
Seems like you can use the prefs:<area> URL to open the settings and go to specific areas. Apple could change these and break your app so always check if you can open them first.
From this article they have listed some of them for iOS 13.1:
Settings URLs
iCloud
prefs:root=CASTLEprefs:root=CASTLE&path=BACKUPWireless Radios
prefs:root=WIFIprefs:root=Bluetoothprefs:root=MOBILE_DATA_SETTINGS_IDPersonal Hotspot
prefs:root=INTERNET_TETHERINGprefs:root=INTERNET_TETHERING&path=Family%20Sharingprefs:root=INTERNET_TETHERING&path=Wi-Fi%20PasswordVPN
prefs:root=General&path=VPNNotifications
prefs:root=NOTIFICATIONS_IDprefs:root=NOTIFICATIONS_ID&path=Siri%20SuggestionsSounds
prefs:root=Soundsprefs:root=Sounds&path=RingtoneDo Not Disturb
prefs:root=DO_NOT_DISTURBprefs:root=DO_NOT_DISTURB&path=Allow%20Calls%20FromScreen Time
prefs:root=SCREEN_TIMEprefs:root=SCREEN_TIME&path=DOWNTIMEprefs:root=SCREEN_TIME&path=APP_LIMITSprefs:root=SCREEN_TIME&path=ALWAYS_ALLOWEDGeneral
prefs:root=Generalprefs:root=General&path=Aboutprefs:root=General&path=SOFTWARE_UPDATE_LINKprefs:root=General&path=CARPLAYprefs:root=General&path=AUTO_CONTENT_DOWNLOADprefs:root=General&path=MULTITASKINGprefs:root=General&path=DATE_AND_TIMEprefs:root=General&path=Keyboardprefs:root=General&path=Keyboard/KEYBOARDSprefs:root=General&path=Keyboard/Hardware%20Keyboardprefs:root=General&path=Keyboard/USER_DICTIONARYprefs:root=General&path=Keyboard/ReachableKeyboardprefs:root=General&path=INTERNATIONALprefs:root=General&path=DICTIONARYprefs:root=General&path=ManagedConfigurationListprefs:root=General&path=ResetControl Center
prefs:root=ControlCenterprefs:root=ControlCenter&path=CUSTOMIZE_CONTROLSDisplay
prefs:root=DISPLAYprefs:root=DISPLAY&path=AUTOLOCKprefs:root=DISPLAY&path=TEXT_SIZEAccessibility
prefs:root=ACCESSIBILITYWallpaper
prefs:root=WallpaperSiri
prefs:root=SIRIApple Pencil
prefs:root=PencilFace ID
prefs:root=PASSCODEEmergency SOS
prefs:root=EMERGENCY_SOSBattery
prefs:root=BATTERY_USAGEprefs:root=BATTERY_USAGE&path=BATTERY_HEALTHPrivacy
prefs:root=Privacyprefs:root=Privacy&path=LOCATIONprefs:root=Privacy&path=CONTACTSprefs:root=Privacy&path=CALENDARSprefs:root=Privacy&path=REMINDERSprefs:root=Privacy&path=PHOTOSprefs:root=Privacy&path=MICROPHONEprefs:root=Privacy&path=SPEECH_RECOGNITIONprefs:root=Privacy&path=CAMERAprefs:root=Privacy&path=MOTION\App Store
prefs:root=STOREprefs:root=STORE&path=App%20Downloadsprefs:root=STORE&path=Video%20AutoplayWallet
prefs:root=PASSBOOKPasswords & Accounts
prefs:root=ACCOUNTS_AND_PASSWORDSprefs:root=ACCOUNTS_AND_PASSWORDS&path=FETCH_NEW_DATAprefs:root=ACCOUNTS_AND_PASSWORDS&path=ADD_ACCOUNTprefs:root=MAILprefs:root=MAIL&path=Previewprefs:root=MAIL&path=Swipe%20Optionsprefs:root=MAIL&path=NOTIFICATIONSprefs:root=MAIL&path=Blockedprefs:root=MAIL&path=Muted%20Thread%20Actionprefs:root=MAIL&path=Blocked%20Sender%20Optionsprefs:root=MAIL&path=Mark%20Addressesprefs:root=MAIL&path=Increase%20Quote%20Levelprefs:root=MAIL&path=Include%20Attachments%20with%20Repliesprefs:root=MAIL&path=Signatureprefs:root=MAIL&path=Default%20AccountContacts
prefs:root=CONTACTSCalendar
prefs:root=CALENDARprefs:root=CALENDAR&path=Alternate%20Calendarsprefs:root=CALENDAR&path=Syncprefs:root=CALENDAR&path=Default%20Alert%20Timesprefs:root=CALENDAR&path=Default%20CalendarNotes
prefs:root=NOTESprefs:root=NOTES&path=Default%20Accountprefs:root=NOTES&path=Passwordprefs:root=NOTES&path=Sort%20Notes%20Byprefs:root=NOTES&path=New%20Notes%20Start%20Withprefs:root=NOTES&path=Sort%20Checked%20Itemsprefs:root=NOTES&path=Lines%20%26%20Gridsprefs:root=NOTES&path=Access%20Notes%20from%20Lock%20ScreenReminders
prefs:root=REMINDERSprefs:root=REMINDERS&path=DEFAULT_LISTVoice Memos
prefs:root=VOICE_MEMOSPhone
prefs:root=PhoneMessages
prefs:root=MESSAGESFaceTime
prefs:root=FACETIMEMaps
prefs:root=MAPSprefs:root=MAPS&path=Driving%20%26%20Navigationprefs:root=MAPS&path=TransitCompass
prefs:root=COMPASSMeasure
prefs:root=MEASURESafari
prefs:root=SAFARIprefs:root=SAFARI&path=Content%20Blockersprefs:root=SAFARI&path=DOWNLOADSprefs:root=SAFARI&path=Close%20Tabsprefs:root=SAFARI&path=CLEAR_HISTORY_AND_DATAprefs:root=SAFARI&path=Page%20Zoomprefs:root=SAFARI&path=Request%20Desktop%20Websiteprefs:root=SAFARI&path=Readerprefs:root=SAFARI&path=Cameraprefs:root=SAFARI&path=Microphoneprefs:root=SAFARI&path=Locationprefs:root=SAFARI&path=ADVANCEDNews
prefs:root=NEWSHealth
prefs:root=HEALTHShortcuts
prefs:root=SHORTCUTSMusic
prefs:root=MUSICprefs:root=MUSIC&path=com.apple.Music:CellularDataprefs:root=MUSIC&path=com.apple.Music:OptimizeStorageprefs:root=MUSIC&path=com.apple.Music:EQprefs:root=MUSIC&path=com.apple.Music:VolumeLimitTV
prefs:root=TVAPPPhotos
prefs:root=PhotosCamera
prefs:root=CAMERAprefs:root=CAMERA&path=Record%20Videoprefs:root=CAMERA&path=Record%20Slo-moBooks
prefs:root=IBOOKSGame Center
prefs:root=GAMECENTER