-3

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.

Pratik B
  • 1,599
  • 1
  • 15
  • 32
user1894820
  • 61
  • 1
  • 3

1 Answers1

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];
Community
  • 1
  • 1
hd1
  • 33,938
  • 5
  • 80
  • 91