-3

如果我输入电话号码,我想在 iPhone 中获取该电话号码的运营商名称和位置。谁能告诉我如何在 xcode 中以编程方式执行此操作。谢谢。

4

1 回答 1

3

根据这个问题,您可以使用以下代码获取用户的运营商信息:

#import <CoreTelephony/CTTelephonyNetworkInfo.h>
// your code goes here
CTTelephonyNetworkInfo *netinfo = [[CTTelephonyNetworkInfo alloc] init];
CTCarrier *carrier = [netinfo subscriberCellularProvider];
NSLog(@"Carrier Name: %@", [carrier carrierName]);
[netinfo release];
// here's how you post it to a URL, presumably the endpoint puts the carrier name and number in a remote database
NSString *myRequestString = [NSString stringWithFormat:@"&carrier=%@&userId=%@", [carrier carrierName],  [[NSUserDefaults standardUserDefaults] stringForKey:@"SBFormattedPhoneNumber"]];
NSData *myRequestData = [NSData dataWithBytes: [myRequestString UTF8String] length: [myRequestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"http://my.webservice.th.at/will/persist/user/info/somewhere"]];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: myRequestData];
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
[myRequestString release];
[request release];
于 2012-12-12T05:40:10.080 回答