0

Is it possible to spoof network providers just like it is possible to spoof locations in iOS?

I have an app that will get a user's ISO country code using Core Location, however I would like a fallback for when the user doesn't authorize location services for my app.

I have a function that is called in order to set a user's country according to their carrier; see below.

- (void)carrierBasedLocationSet {
if (DefaultCountryCode && ![DefaultCountryCode isEqualToString:@"Default"]) {
    ////NSLog(@"Skip Carrier Based Location set : DefaultCountryCode is [%@]", DefaultCountryCode);
    return;
}
/***********************************
 * Set country code based on Carrier
 ***********************************/
CTTelephonyNetworkInfo *networkInfo = [[CTTelephonyNetworkInfo alloc] init];
Carrier = [networkInfo subscriberCellularProvider];
NSString *isoCountryCode = Carrier.isoCountryCode;
if (isoCountryCode == nil || isoCountryCode.length == 0) {
    isoCountryCode = [[NSLocale currentLocale] objectForKey:NSLocaleCountryCode];
}
self.ISO_CountryCode = [isoCountryCode uppercaseString];
self.CarrierBased_ISO_Country = self.ISO_CountryCode;

}

This code works and produces US, which is where I am located. However, I want to test this out for different countries. Simply editing the product scheme to spoof a location in Australia, for example, does not give me back the AU country code and still gives me US.

Does anyone know if what I am trying to do is possible? Getting a user's location is essential to my application and I am unsure of another alternative.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
romero-ios
  • 1,075
  • 1
  • 11
  • 20
  • You cannot if you use `CTTelephonyNetworkInfo ` to get carrier info, AFAIK. Have you thought about extending `CTTelephonyNetworkInfo` to override its `subscriberCellularProvider` method? – volatilevar Jan 04 '17 at 15:49
  • I have not thought of this, not much experience using the framework. So with that approach I can just look up a foreign carrier name and set that as my simulator's carrier? – romero-ios Jan 04 '17 at 16:28
  • 1
    Rather than spoof the carrier, you might find it easier to just [use the time zone](http://stackoverflow.com/questions/19186666/get-timezone-country-from-iphone/19190185#19190185). – Tom Harrington Jan 04 '17 at 18:48
  • @danielx0328 Yes, that's what I meant, but Tom's answer is much better/easier. – volatilevar Jan 04 '17 at 20:52

0 Answers0