如何判断用户是否关闭了我的应用的移动数据网络? [英] How to tell if the user turned off cellular data for my app?

查看:319
本文介绍了如何判断用户是否关闭了我的应用的移动数据网络?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我的应用程式可在没有任何网际网路连线的情况下使用,但可能会与网路伺服器交换资料(以显示部分使用者统计资料)。所以我宣传的应用程序不需要互联网连接。有些用户随后关闭了我的应用的移动数据网络,这应该是完全正常的。但是当我的应用程序尝试交换数据时,这些用户被错误设置为应用名称的蜂窝数据已关闭。对话框。

Although my app is usable without any internet connection, it may exchange data with a web server (in order to show some user statistics). So I advertise the app as "needs no internet connection". Some users subsequently have turned off cellular data for my app, which should be completely fine. But when my app tries to exchange data, these users are bugged with the "Cellular data is turned off for [App Name]." dialog.

这是一个麻烦,我想阻止这些对话框,只是跳过整个数据交换的东西。

This is an annoyance to them and I want to prevent these dialogs and simply skip the whole data exchange thing.

Apple的可达性示例代码

但是,虽然我关闭了整个设备的WiFi和应用程序的蜂窝数据,Reachability确认一个积极的互联网连接。更具体地,它报告

But although I turned off WiFi for the whole device and cellular data for the app, Reachability confirms a positive internet connection. To be more specific, it reports

Reachability Flag Status: WR t------ networkStatusForFlags

无论我是否激活蜂窝数据。当然,当蜂窝数据被关闭时,没有互联网连接实际上可用,因此数据交换失败。

no matter whether I activated cellular data or not. Of course, when cellular data is turned off, no internet connection is actually available, so the data exchange fails. But the user is presented with the cellular data dialog anyway.

有任何方法可以检测iOS 7和iOS 8上的互联网连接是否可用,同时考虑到针对特定应用的移动数据设置 - 所有这一切都不会再次通过移动数据对话框向用户发送错误消息?

Is there any way to detect whether a internet connection is available on iOS 7 and iOS 8, taking into account the cellular data setting for a specific app – all without bugging the user every time again with the cellular data dialog?

我的应用目前没有任何设置面板,因此我想避免设置(第二个,应用内)开关不使用蜂窝数据。此外,我不想限制数据交换到WiFi连接,因为它只是一个2 KB的数据每个会话对大多数用户来说不是一件大事。

My app currently comes without any settings panel, so I want to avoid setting up a (second, in-app) switch "don't use cellular data". Also, I don't want to restrict data exchange to a WiFi connection since it's just a 2 KB of data per session which isn't a big thing for most users.

推荐答案

我认为在iOS8中唯一支持的方式是发送Ping到一个已知的服务器,并用警报面板几次错误的用户。在iOS8上,Apple只显示面板两次,然后跳过它,即使应用程序重新启动,也许它会在一天后再次显示。 (这对于支持广告的应用来说真是个坏消息。)

I think the only supported way in iOS8 is to send a Ping to a known server and bug the user with the alert panel a few times. On iOS8, Apple displays the panel only twice, then skips it even if the app is restarted, maybe it will show up a day later again. (This is really bad news for ad-supported apps.)

Apple说( https://devforums.apple.com/message/1059332#1059332 ):


另一个开发人员写入DTS,因此我有机会对
进行深入调查。唉,这个消息是我预期的:
没有支持的方式来检测你的应用程序处于这种状态。
也没有办法做一个无用户交互网络连接,
也就是说,请求连接失败,而不是像
这样的现在UI。

Another developer wrote in to DTS and thus I had a chance to investigate this in depth. Alas, the news is much as I expected: there is no supported way to detect that your app is in this state. Nor is there a way to make a "no user interaction" network connection, that is, request that the connection fail rather than present UI like this.

以下文章建议使用ping的方法:

The following articles suggest ways to use ping:

http://www.splinter.com.au/how-to-ping- a-server-in-objective-c-iphone /

http://elbsolutions.com/projects/reachability-with-simpleping-wrapper/

这篇关于如何判断用户是否关闭了我的应用的移动数据网络?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆