Open Settings app from another app programmatically in iPhone

前端 未结 6 914
陌清茗
陌清茗 2020-12-07 18:55

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

6条回答
  •  感动是毒
    2020-12-07 19:42

    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.

提交回复
热议问题