首页 > 代码库 > iOS 获取城市IP
iOS 获取城市IP
NSString *IP =@"0.0.0.0";
//http://61.4.185.48:81/g/(中国天气网的接口)
NSURL *url = [NSURLURLWithString:@"http://61.4.185.48:81/g/"];
NSURLRequest *request = [NSURLRequestrequestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicytimeoutInterval:1.0];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = http://www.mamicode.com/[NSURLConnectionsendSynchronousRequest:request returningResponse:&response error:&error];
if (error) {
NSLog(@"Failed to get WAN IP Address!\n%@", error);
}else {
NSString *responseStr = [[NSStringalloc] initWithData:dataencoding:NSUTF8StringEncoding];
IP = responseStr;
}
NSLog(@"%@",IP);
return IP;
iOS 获取城市IP