有没有办法判断iphone是否处于漫游状态?

发布于 2024-07-21 00:50:33 字数 1395 浏览 7 评论 0原文

我正在开发一个 iPhone 应用程序,并且非常想确定该设备是否正在漫游,以便我可以智能地避免用户在脱离家庭网络时花费昂贵的连接费用。

我正在编写的应用程序适用于越狱手机,但如果可能的话,我更愿意使用标准 SDK。

这是我已经发现的:

1。 苹果 SDK: 在苹果文档中,我在苹果的 SCNetworkReachability API 中找到了承诺。 该 API 提供对诸如您是否在 WIFI 还是手机网络、当前是否建立网络连接等信息的访问。但是,在 SCNetworkReachability API 参考 pdf 中搜索“漫游”或“漫游”,结果均为零。 他们的示例代码也是如此。

2. 越狱 iPhone FS 的 Grep: 偏好-> 一般-> 网络选项卡是用户可以打开或关闭漫游的地方。 在 plist 文件中查找此内容(“/Applications/Preferences/Network.plist”),我能够找到以下参考文献:

        PostNotification = "com.apple.commcenter.InternationalRoamingEDGE.changed";
        cell = PSSwitchCell;
        default = 1;
        defaults = "com.apple.commcenter";
        key = InternationalRoamingEDGE;
        label = "EDGE_ROAMING_TOGGLE";
        requiredCapabilities =             (
            telephony
        );

这当然是一个线索,因为看起来我可以注册用户已更改 InternationalRoaming 的通知设置。 不过,我不确定如何将其转化为他们实际上目前正在漫游的知识。

3. 检查SpringBoard的类转储源: 我已经使用 class-dump 转储了 SpringBoard 的类。 我找不到任何有关“漫游”或“漫游”的参考

4。 显然,我首先在 SO 上检查了这一点: 找不到任何相关内容。

进一步的步骤:这里有人有什么建议吗? 我知道这是可能的。 然而,苹果显然让它变得非常难以找到。 我非常怀疑如果不使用私有框架这是可能的。 (例如 CoreTelephony)。 由于这是一个越狱的应用程序,我可能会通过在 SpringBoard 中注入代码来屏幕抓取运营商名称,但我真的宁愿不走这条路。 非常感谢任何建议。 谢谢。

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.

The application I am writing is for jailbroken phones, however I would prefer to use standard SDKs if possible.

Here is what I've already found:

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. 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. 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. Obviously I started by checking at SO for this:
Couldn't find anything related.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

扛起拖把扫天下 2024-07-28 00:50:33

有! 它根本没有记录,我非常怀疑这是否适用于未越狱的手机(因为它需要使用不在沙箱中的文件)。 然而,这是如何完成的。

iPhone 文件系统保留两个软链接:

static NSString *carrierPListSymLinkPath = @"/var/mobile/Library/Preferences/com.apple.carrier.plist";
static NSString *operatorPListSymLinkPath = @"/var/mobile/Library/Preferences/com.apple.operator.plist";

当这些链接指向同一文件时,电话不会漫游。 当指向不同的文件时,电话正在漫游。

简化的代码(无错误检查等):

- (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]);
}

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.

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]);
}
送舟行 2024-07-28 00:50:33

符号链接的解决方案不是唯一的方法,但绝对是最好的方法。 正如我刚刚意识到的,返回的字符串包含运营商和承运商的 MCC 和 MNC 代码! 即使是核心电话框架也无法检索有关您的 iPhone 在漫游时所连接的运营商的信息。

 Logs: 
 carrier: /System/Library/Carrier Bundles/iPhone/72410/carrier.plist
 operator: /System/Library/Carrier Bundles/iPhone/20810/carrier.plist

如您所见,运营商(原始蜂窝提供商)行包含“文件夹”72410 内的文件,这意味着 MCC 724(巴西)和 MNC 10(VIVO)。
运营商(实际上是我的手机现在连接的 - 我正在漫游)位于文件夹 20810 内,这意味着 MCC 208(法国)和 MNC 10(SFR)。

顺便说一句,我使用的是装有 iOS5 的 iPhone 4。

the solution of the symlinks are not the only way to do it but definitely it is the best. As I just realized, the Strings returned contains the MCC and MNC codes of the operator and carrier!!! Even the core telephony framework is not able to retrieve those informations about the operator your iPhone is attached when in roaming.

 Logs: 
 carrier: /System/Library/Carrier Bundles/iPhone/72410/carrier.plist
 operator: /System/Library/Carrier Bundles/iPhone/20810/carrier.plist

As you can see, the carrier (original cellular provider) line contains the file inside the "folder" 72410, which means MCC 724 (Brazil) and MNC 10 (VIVO).
The operator (actually the one my cell phone is attached now - i'm in roaming) is inside the folder 20810, which means MCC 208 (France) and MNC 10 (SFR).

By the way, I'm using iPhone 4 with iOS5.

自由范儿 2024-07-28 00:50:33

在非越狱设备上,您可以使用第三方服务,例如 http://ipinfo.io (我自己的服务)来查找根据设备的 IP 地址找出当前所在国家/地区的运营商代码,然后您可以将其与 CTCarrier 详细信息进行比较,以确定设备是否正在漫游。 以下是标准 ipinfo.io API 响应:

$ curl ipinfo.io/24.32.148.1 
{
    "ip": "24.32.148.1",
    "hostname": "doc-24-32-148-1.pecos.tx.cebridge.net",
    "city": "Pecos",
    "region": "Texas",
    "country": "US",
    "loc": "31.3086,-103.5892",
    "org": "AS7018 AT&T Services, Inc.",
    "postal": "79772"
}

可以使用自定义包,其中还包括移动 IP 的 mnc/mcc 详细信息。 有关详细信息,请参阅 http://ipinfo.io/developers

On a non-jailbreak device you can use third party services like http://ipinfo.io (my own service) to find out the current country of even carrier code based on the device's IP address, and you can then compare that to the CTCarrier details to determine if the device is roaming. Here's the standard ipinfo.io API response:

$ curl ipinfo.io/24.32.148.1 
{
    "ip": "24.32.148.1",
    "hostname": "doc-24-32-148-1.pecos.tx.cebridge.net",
    "city": "Pecos",
    "region": "Texas",
    "country": "US",
    "loc": "31.3086,-103.5892",
    "org": "AS7018 AT&T Services, Inc.",
    "postal": "79772"
}

Custom packages are available that also include the mnc/mcc details of mobile IPs though. See http://ipinfo.io/developers for details.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文