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;</pre>
本文由用戶 ew3y 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!