if i enter the phone number i want to get the carrier name of that phone number and location in iPhone.Can anyone please tell me how can i do this programatically in xcode.Thanks.
Asked
Active
Viewed 2,992 times
1 Answers
3
According to this question, you can get the user's carrier information with the code below:
#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];
-
The `SBFormattedPhoneNumber` was removed a long time ago. It is no longer available. – rmaddy Dec 12 '12 at 06:08