码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 获取城市IP

时间:2015-01-06 15:43:12      阅读:154      评论:0      收藏:0      [点我收藏+]

标签: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;


iOS 获取城市IP

标签:ios ip 外网

原文地址:http://blog.csdn.net/sun_winter/article/details/42458215

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!