问题描述
我正在开发一个iPhone应用程序,并且非常想确定设备是否正在漫游,这样我就可以智能地避免在用户家庭网络之外花费昂贵的连接。
I am working on an iPhone application and would really like to determine if the device is roaming so that I can intelligently avoid costing my users expensive connections if out of their home network.
我写的应用程序适用于越狱手机,但如果可能,我更愿意使用标准SDK。
The application I am writing is for jailbroken phones, however I would prefer to use standard SDKs if possible.
这是我已经找到的:
1。 Apple SDKs:
在Apple文档中,我在Apple的SCNetworkReachability API中找到了承诺。通过API,您可以访问WIFI或手机网络,当前是否建立了网络连接等。但是,搜索SCNetworkReachability API参考pdf以获取漫游或漫游两者均为零。他们的示例代码也是如此。
1. Apple SDKs:In the apple documentation, I found the promise in Apple's SCNetworkReachability API. The API provides access to such things as whether you are on a WIFI or a cell phone network, whether a network connection is currently established, etc. However searching the SCNetworkReachability API reference pdf for 'roam' or 'roaming' both turn up nil. So does their sample code.
2。越狱iPhone FS的Grep:
首选项 - >常规 - >网络选项卡是用户可以打开或关闭漫游的地方。在plist文件中查找(/Applications/Preferences/Network.plist)我能够找到以下引用:
2. Grep of a Jailbroken iPhone FS:The preferences -> general -> networking tab is where users can turn on or off their roaming. Looking in the plist file for this ("/Applications/Preferences/Network.plist") I was able to find the following references:
PostNotification = "com.apple.commcenter.InternationalRoamingEDGE.changed";
cell = PSSwitchCell;
default = 1;
defaults = "com.apple.commcenter";
key = InternationalRoamingEDGE;
label = "EDGE_ROAMING_TOGGLE";
requiredCapabilities = (
telephony
);
这肯定是一个领先优势,因为看来我可以注册用户已更改的通知国际漫游设置。尽管如此,我不确定如何将其变成他们实际上正在漫游的知识。
This is certainly a lead, as it appears I can sign up for notifications that the user has changed the InternationalRoaming settings. Still, I'm not certain how to turn this into the knowledge that they are in fact, presently roaming.
3。检查SpringBoard的类转储源:
我使用。我无法找到任何漫游或漫游的引用
3. Check the class dumped sources of SpringBoard:I've dumped the classes of SpringBoard using class-dump. I was unable to find any references to 'roam' or 'roaming'
4。显然,我开始在SO处查看:
找不到任何相关内容。
4. Obviously I started by checking at SO for this:Couldn't find anything related.
进一步的步骤:有没有人在这里有任何建议?
我知道这是可能的。但苹果显然很难找到它。我非常怀疑,如果不使用私有框架,这是可能的。 (例如CoreTelephony)。由于这是一个越狱的应用程序,我可能会使用SpringBoard中的注入代码来屏幕抓取运营商名称,但我真的更愿意不去那条路线。任何建议都非常感谢。谢谢。
Further steps: Does anyone have any advice here?I know this is possible. Apple clearly has made it very difficult to find however. I highly doubt this is possible without using a private framework. (such as CoreTelephony). As this is a jailbroken app, I may resort to screen-scraping the the carrier name with injected code in the SpringBoard, but I would really rather prefer not to go that route. Any advice much appreciated. Thanks.
推荐答案
有!它根本没有记录,我非常怀疑这可以在非越狱手机上运行(因为它需要使用不在沙盒中的文件)。但是,这是如何完成的。
There is! It's not documented at all, and I highly doubt this would work on a non-jailbroken phone (as it requires using files not in the sandbox). However, here is how it is done.
iPhone文件系统保留两个软链接:
The iPhone file system keeps two softlinks:
static NSString *carrierPListSymLinkPath = @"/var/mobile/Library/Preferences/com.apple.carrier.plist";
static NSString *operatorPListSymLinkPath = @"/var/mobile/Library/Preferences/com.apple.operator.plist";
当这些链接指向同一个文件时,电话没有漫游。当指向不同的文件时,电话正在徘徊。
when these links are pointing at the same file, the telephone is not roaming. When pointing at different files, the telephone is romaing.
简化代码(无错误检查等):
Simplified code (no error checking, etc):
- (BOOL)isRoaming
{
NSFileManager *fm = [NSFileManager defaultManager];
NSError *error;
NSString *carrierPListPath = [fm destinationOfSymbolicLinkAtPath:carrierPListSymLinkPath error:&error];
NSString *operatorPListPath = [fm destinationOfSymbolicLinkAtPath:operatorPListSymLinkPath error:&error];
return (![operatorPListPath isEqualToString:carrierPListPath]);
}
这篇关于有没有办法确定iPhone是否正在漫游?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!