【问题标题】:How can i get through Mobile Data Settings Programmatically in iOS Swift 3如何在 iOS Swift 3 中以编程方式通过移动数据设置
【发布时间】:2017-07-28 17:57:19
【问题描述】:

我正在尝试访问移动数据/蜂窝数据设置页面,该页面列出了所有可以访问移动/蜂窝数据或互联网的应用程序。

我尝试了以下代码:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


        let currentCell = featuresTable.cellForRow(at: indexPath)! as! HomeTableViewCell

        if(currentCell.featureName!.text == "Internet Permissions")
        {
            // The code to enter the mobile data settings 

            let url = URL(string: "App-Prefs:root=MOBILEDATA")
            let app = UIApplication.shared
            app.openURL(url!)

        }
    }

Here the Output i want:

【问题讨论】:

    标签: ios swift settings openurl


    【解决方案1】:

    这是可能的。!但标准方法是始终打开您的应用程序设置屏幕,该屏幕由以下代码完成。所有应用程序(如 Uber、Facebook 等)都使用以下方法。 下面的代码写在

    斯威夫特 3 此外,代码还检查 ios 版本并为所有版本完成工作,还有一点解释性

    if let url = URL(string: UIApplicationOpenSettingsURLString){
            if #available(iOS 10.0, *){
                UIApplication.shared.open(url, completionHandler: nil)
                print("\n--- in ios 10 ")
            } else{
                UIApplication.shared.openURL(url)
                print("\n--- in ios other than 10 ")
            }
        }
    

    UIApplicationOpenSettingsURLString : 基本上打开你的应用程序的设置,它还显示应用程序正在使用的所有服务,包括位置服务、移动数据、照片库等......

    现在将 Cocoa Keys 添加到您的应用程序中,即在 plist 文件中 这里有一些网址 Cocoa keys for iOS 10, Cocoa Keys from developer.apple

    希望对你有帮助...

    【讨论】:

    • 但是 Viber 做到了。关闭所有互联网连接,您将收到带有两个按钮的警报。按下设置按钮,您将进入蜂窝设置...
    • 更新了答案。@Ruzin 这是在 iOS 中打开特定设置的答案:stackoverflow.com/a/33371820/4598318
    【解决方案2】:

    我不确定移动数据。

    您可以如下打开应用设置

    UIApplication.shared.openURL(URL(String:UIApplicationOpenSettingsURLString))
    

    【讨论】:

    • 这是打开我当前应用的设置,我需要访问所有应用
    猜你喜欢
    • 2018-01-06
    • 1970-01-01
    • 2014-03-01
    • 2023-03-10
    • 2016-09-28
    • 1970-01-01
    • 2012-04-19
    • 2017-09-16
    • 2011-12-19
    相关资源
    最近更新 更多