iOS 获取城市IP
NSString *IP = @"0.0.0.0";
//http://61.4.185.48:81/g/(中国天气网的接口)
NSURL *url = [NSURL URLWithString:@"http://61.4.185.48:81/g/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:1.0];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error) {
NSLog(@"Failed to get WAN IP Address!\n%@", error);
} else {
NSString *responseStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
IP = responseStr;
}
NSLog(@"%@",IP);
return IP;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。