簡體   English   中英

UIAlertView就像“打開位置服務以允許地圖確定您的位置”。 設置+取消

[英]UIAlertView like “Turn On Location Services to allow maps to determine your location”. Settings + Cancel

我想發出此警報:

Turn On Location Services to allow maps to determine your location

我需要“設置”和“取消”,就像“地圖”應用程序一樣。

“設置”應該打開設置 - >常規 - >位置服務

我沒有找到打開設置頁面的方法。

你能幫助我嗎?

謝謝

創建警報非常簡單,它只是一個(仿)模式UIView。

但是, 無法以編程方式打開“設置”應用,至少在沒有使用會阻止您的應用被批准用於App Store的私有方法的情況下。

您無法打開常規,Locatios等特定設置頁面,但您可以在iOS 8中打開設置頁面。

  - (void)openSettings
  {
      BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
      if (canOpenSettings)
      {
          NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
          [[UIApplication sharedApplication] openURL:url];
      }
  }

這是不可能自己完成的。 但是,如果您的應用程序需要訪問位置服務,操作系統將為您顯示如下對話框,如下所示。

編輯:下面提到的Brant“可以通過在CLLocationManager上設置目的屬性的值來自定義消息。”

替代文字

Swift 2.0版本:

func showLocationSettingAlert() {
    let alertController = UIAlertController(
        title:  "Location Access Disabled",
        message: "Location settings",
        preferredStyle: .Alert)

    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
    alertController.addAction(cancelAction)

    let openAction = UIAlertAction(title: "Open Settings", style: .Default) { (action) in
        if let url = NSURL(string:UIApplicationOpenSettingsURLString) {
            UIApplication.sharedApplication().openURL(url)
        }
    }
    alertController.addAction(openAction)
    self.presentViewController(alertController, animated: true, completion: nil)
}

此時無法以編程方式打開設置窗格。 請參閱此處

這不是你添加的東西。 當應用程序想要使用位置服務但在設置中關閉時,會出現該屏幕。

推送通知也會發生同樣的事情。

其他人怎么說,如果你想在app Store上使用你的應用,你就不能以編程方式打開設置應用。
如果應用程序支持並使用定位服務等已確定的功能,則會在啟動應用時自動“生成”此彈出窗口。
您可以在參考資料庫中找到有關此服務的更多信息: https//developer.apple.com/library/ios/navigation/#section=Frameworks&topic=CoreLocation

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM