可达性和国际漫游 [英] Reachability and International Roaming
问题描述
我使用来自Apple的 Reachability
类来确定数据或wifi是否可用。但是,用户(使用美国iPhone)正在另一个国家/地区测试该应用,并且在尝试访问MapKit时出现以下错误。
I am using the Reachability
class from Apple to determine whether or not data or wifi is available. However, a user (with a U.S. iPhone) is testing the app in another country and he is seeing the following error while trying to access the MapKit.
在我对这个错误的研究中,我发现 PBRequester
是 ProtocolBuffer 。
In my research on this error, I have found that PBRequester
is ProtocolBuffer.
2012-10-15 21:16:00.921 WrightsCS App [24239:907] PBRequester失败,错误错误域= kCFErrorDomainCFNetwork Code = -1018国际漫游目前关闭。 UserInfo = 0x1e5587d0 {NSErrorFailingURLKey = https://gsp13-cn.ls.apple.com/shift,NSErrorFailingURLStringKey = https://gsp13-cn.ls.apple.com/shift,NSLocalizedDescription =国际漫游目前已关闭。}
2012-10-15 21:16:00.921 WrightsCS App[24239:907] PBRequester failed with Error Error Domain=kCFErrorDomainCFNetwork Code=-1018 "International roaming is currently off." UserInfo=0x1e5587d0 {NSErrorFailingURLKey=https://gsp13-cn.ls.apple.com/shift, NSErrorFailingURLStringKey=https://gsp13-cn.ls.apple.com/shift, NSLocalizedDescription=International roaming is currently off.}
示例
Example
-(BOOL)hasDataConnection
{
Reachability *networkReachability = [Reachability reachabilityForInternetConnection];
NetworkStatus networkStatus = [networkReachability currentReachabilityStatus];
if ( networkStatus == NotReachable )
{
return NO;
}
else
{
if ( ! [Reachability reachabilityWithHostName:@"www.google.com"] )
return NO;
return YES;
}
}
问题
我们如何检测用户是否正在漫游,或者至少确保在用户漫游时不会遇到此错误?
Question
How can we detect if the user is roaming or at least ensure that we do not encounter this error if by chance the user is roaming?
推荐答案
确定 - 这不是一个答案,但可能指向正确的方向。首先,我找不到Objective C类似乎允许你这样做(例如 NSURLRequest
Class)。
OK - this is not an answer but may point you in the right direction. To start with, I can't find an Objective C class that seems to let you do this (e.g. NSURLRequest
Class).
我认为您需要直接前往CFNetwork Framework (CFNetwork Framework Reference),因为查看CFNetworkError代码有这些诱人的条目(它们匹配您的错误消息):
I think you will need to go directly to the CFNetwork Framework (CFNetwork Framework Reference) because looking at the CFNetworkError codes has these tantalising entries (which match your error message):
kCFURLErrorNotConnectedToInternet = -1009,
kCFURLErrorInternationalRoamingOff = -1018,
kCFURLErrorDataNotAllowed = -1020,
不幸的是,我不知道CFNetwork框架,尽管看看苹果文档我不知道哪个CFNetwork框架API使用这些值。但我相信会有办法。
Unfortunately, I don't know the CFNetwork Framework and despite looking at the Apple docs I am no wiser about which CFNetwork Framework API's use these values. But I am convinced there will be a way.
我的两个想法(我很宽松地使用这个词):
My two "ideas" (and I use that word loosely):
- 使用
CFHost
(并获取回调查询错误代码) -
CFNetDiagnosticCopyNetworkStatusPassively
(并解析返回的字符串)。
- Use
CFHost
(and get a callback to query for the error code) - Use
CFNetDiagnosticCopyNetworkStatusPassively
(and parse the returned string).
如果有专家,真正的答案。
I would love to see the real answer if there's an expert out there.
这篇关于可达性和国际漫游的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!