首页 > 解决方案 > iOS:13 位置始终允许:点击打开设置后,它不会重定向到应用设置页面

问题描述

我需要打开我的应用程序设置,但有时如果我们打开了将其他屏幕设置为 wifi 或代理屏幕,那么它不会重定向到 iOS 13 中的应用程序设置。

@IBAction func openPhoneSettings(_ sender: Any) {
    guard let settingsUrl = URL(string: UIApplication.openSettingsURLString),
        UIApplication.shared.canOpenURL(settingsUrl) else {
            return
    }

    UIApplication.shared.open(settingsUrl, options: [:]) { (canOpen) in
        self.dismiss(animated: false, completion: nil)
    }
}

标签: iosobjective-cswiftios13

解决方案


我为打开应用程序设置创建了功能,这对我来说在所有情况下都可以重定向到应用程序设置

func openAppSetting()
{
   guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {return}

   if UIApplication.shared.canOpenURL(settingsUrl) 
   {
      if #available(iOS 10.0, *) 
      {
          UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
                        print("Settings opened: \(success)")
                    })
      } 
      else 
      {
         UIApplication.shared.openURL(settingsUrl as URL)
      }
   } 
   else 
   {
       print("Settings not opened")
   }
}

我希望这个能帮上忙...!


推荐阅读