iOS获取城市IP
发表时间:2020-10-19
发布人:葵宇科技
浏览次数:47
NSLog(@"Failed to get WAN IP Address!\n%@", error);
NSString *IP = @"0.0.0.0";
//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 = http://www.sjsjw.com/100/000045MYM005578/[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if (error) {
} else {
NSString *responseStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
IP = responseStr;
}
NSLog(@"%@",IP);
return IP;
NSURL *url = [NSURL URLWithString:@"http://61.4.185.48:81/g/"];