iOS程序化蜂窝数据控制

编程入门 行业动态 更新时间:2024-10-28 05:14:06
本文介绍了iOS程序化蜂窝数据控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有一种方法可以通过编程方式访问蜂窝数据"?有时会显示在应用程序中的选项吗?

Is there a way to programmatically access the "Cellular Data" options that are sometimes shown in apps?

我有一个通过Internet上传数据文件的应用程序.我为用户提供了在不连接WiFi时禁用此上传功能的选项.

I have an application that uploads data files over the internet. I have given users the option of disabling this upload functionality when not connected to WiFi.

我目前正在做的是写了一个settings.bundle,它允许用户在我的代码中选择一个名为 User Cellular Data 的选项.我正在使用(c href ="github/ashleymills/Reachability.swift" rel ="nofollow noreferrer"> github/ashleymills/Reachability.swift )-这是围绕可达性iOS API-基本上可以告诉您是否有Wifi或蜂窝网络访问.

What I'm currently doing is I wrote a settings.bundle that allows the user to select an option called User Cellular Data in my code I am using a Reachability.swift file from (github/ashleymills/Reachability.swift) - which is a swift wrapper around the reachability iOS api - basically it can tell you if there is Wifi or cellular network access.

在执行上传操作之前,我在代码中检查了NSUserDefaults值(由settings.bundle设置)

In my code before doing uploads I check a NSUserDefaults value (as set by the settings.bundle)

let uploadOverCellular = NSUserDefaults.standardUserDefaults() .boolForKey("allow_upload_over_cellular")

如果这是真的,并且我具有Wifi或蜂窝网络,则允许上传继续进行.如果情况并非如此,并且我具有蜂窝网络,我将停止上传.

If this is true and I have either Wifi or Cellular internet I allow the upload to proceed. If this is not true and I have cellular internet I stop the upload.

所以这很好,然后突然我在查看应用程序的设置,发现我同时具有系统级蜂窝数据选项和我的自定义使用移动数据选项.出现

So this is working nicely and then suddenly I was looking in the settings for my app and I noticed that I have both the System level Cellular Data option as well as my custom Use Cellular Data option. showing up

显然,这可能给用户带来一些困惑-我想知道是否可以通过API访问此系统级别的 Cellualr Data 选项-或通过其他方式进行控制以编程方式设置此设置-我怀疑没有,但是我希望有人能证明我做错了.

Obviously this could cause some confusion for users - I wanted to know if there Is there API access to this system level Cellualr Data option - or some other way to control this setting programmatically - I suspect there is not but I'm hoping somebody can prove me wrong.

推荐答案

我不知道是否可以访问全局蜂窝数据设置,但是如果使用NSURLSession API下载数据,则可以创建和allowsCellularAccess = false.

I don't know if there's access to the global cellular data setting, but if you use NSURLSession APIs for downloading data, you can create an NSURLSessionConfiguration with allowsCellularAccess = false.

更多推荐

iOS程序化蜂窝数据控制

本文发布于:2023-11-26 19:48:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634958.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:蜂窝   数据   iOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!