Is there any way to determine if the iphone is roaming?

前端 未结 3 1694
太阳男子
太阳男子 2020-11-28 06:38

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

3条回答
  •  被撕碎了的回忆
    2020-11-28 06:58

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

提交回复
热议问题