iOS 根据IP获取位置
作者:
KyleLou | 来源:发表于
2018-03-06 15:23 被阅读68次
- (NSString *)getWANIP {
//通过淘宝提供的服务,定位WAN的IP
NSURL *ipURL = [NSURL URLWithString:@"http://ip.taobao.com/service/getIpInfo.php?ip=myip"];
NSData *data = [NSData dataWithContentsOfURL:ipURL];
NSDictionary *ipDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSString *ipStr = nil;
NSLog(@"IPDict:%@",ipDict);
//获取成功
if (ipDict && [ipDict[@"code"] integerValue] == 0) {
ipStr = ipDict[@"data"][@"country_id"];
}
return (ipStr ? ipStr : @"");
}
本文标题:iOS 根据IP获取位置
本文链接:https://www.haomeiwen.com/subject/gtfrfftx.html
网友评论