1.下边方法zipCode参数是天气网站里面的一个城市编码,根据zipCode查询
北京的编码是:101010100
+(NSString*)getWeatherXmlForZipCode: (NSString*)zipCode {
NSError *error;
NSURLResponse *response;
NSData *dataReply;
NSString *stringReply;
NSMutableURLRequest *request = [NSMutableURLRequestrequestWithURL: [NSURLURLWithString: [NSStringstringWithFormat:@"http://m.weather.com.cn/data/%@.html", zipCode]]];
[request setHTTPMethod: @"GET"];
dataReply = [NSURLConnectionsendSynchronousRequest:request returningResponse:&responseerror:&error];
stringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
NSLog(stringReply);
return stringReply;
}
2.返回的字符串展示在UIWebView
NSString* weatherXml = [AmuckWeather getWeatherXmlForZipCode:textField.text];
NSData* htmlData = [weatherXml dataUsingEncoding:NSUTF8StringEncoding];
[webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:nil];
调用出现Error调用的方法
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{