1,将聚合数据SDK(JuheApis.framework)添加到你的程序中来,SDK依赖的包包括:
/*** 全国天气预报 ***/
#define kJHAPIS_LIFE_WEATHER_CITYS @"juhe.apis.weather.citys" //6、支持城市列表
3,全国天气预报接口在程序中调用方法(将ViewController.m改为.mm)
#import "ViewController.h"
#import <JuheApis/JuheAPI.h>/* 2. 天气种类及标识列表 */
[self test :kJHAPIS_LIFE_WEATHER_UNI parameters:@{@"dtype":@"json"} ];
/* 3. 根据IP查询天气 */
[self test : kJHAPIS_LIFE_WEATHER_IP parameters:@{@"ip":@"58.215.185.154" , @"dtype":@"json"} ];
/* 4. 根据GPS坐标查询天气 */
[self test :kJHAPIS_LIFE_WEATHER_GEO parameters:@{@"lon":@"116.39277" , @"lat":@"39.933748" , @"dtype":@"json" } ];
/* 5. 城市天气三小时预报 */
[self test :kJHAPIS_LIFE_WEATHER_FORECAST3H parameters:@{@"cityname":@"苏州" , @"dtype":@"json" } ];
/* 6. 支持城市列表 */
[self test :kJHAPIS_LIFE_WEATHER_CITYS parameters:@{@"dtype":@"json" } ];
}
- (void)test:(NSString *)path parameters:(NSDictionary *)parameters{
JuheAPI *juheapi = [JuheAPI shareJuheApi];
[juheapi executeWorkWithAPI:path
parameters:parameters
success:^(id responseObject){
if ([[parameters objectForKey:@"dtype"] isEqualToString:@"xml"]) {
NSLog(@"***xml*** \n %@", responseObject);
}else{
int error_code = [[responseObject objectForKey:@"error_code"] intValue];
if (!error_code) {
NSLog(@" %@", responseObject);
}else{
NSLog(@" %@", responseObject);
}
}
} failure:^(NSError *error) {
NSLog(@"error: %@",error.description);
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
4,全国天气预报接口返回数据说明以及错误码说明
1. 根据城市名/id查询天气
API :juhe.apis.weather.index (宏 : kJHAPIS_LIFE_WEATHER_INDEX )
返回字段 :
名称 |
|
|
类型 |
说明 |
resultcode |
int |
返回码 |
||
reason |
string |
返回说明 |
||
result |
dictionary |
返回结果 |
||
sk |
dictionary |
当前实况天气 |
||
temp |
int |
当前温度 |
||
wind_direction |
string |
当前风向 |
||
wind_strength |
string |
当前风力 |
||
humidity |
string |
当前湿度 |
||
time |
date |
更新时间 |
||
today |
dictionary |
今日天气 |
||
city |
string |
城市 |
||
date_y |
string |
日期 |
||
week |
string |
星期 |
||
temperature |
string |
今日温度 |
||
weather |
string |
今日天气 |
||
weather_id |
dictionary |
天气唯一标识 |
||
fa |
Int |
天气标识00:晴 |
||
fb |
int |
天气标识53:霾 如果fa不等于fb,说明是组合天气 |
||
wind |
string |
风向与风力 |
||
dressing_index |
string |
穿衣指数(较冷) |
||
dressing_advice |
string |
穿衣建议 |
||
uv_index |
string |
紫外线强度 |
||
comfort_index |
string |
舒适度指数 |
||
wash_index |
string |
洗车指数 |
||
travel_index |
string |
旅游指数 |
||
exercise_index |
string |
晨练指数 |
||
drying_index |
string |
干燥指数 |
||
future |
array |
未来几天天气(内部字典参数均能在today中找到) |
||
error_code |
int |
错误码 |
2. 天气种类及标识列表
API :juhe.apis.weather.uni (宏 :kJHAPIS_LIFE_WEATHER_UNI )
返回字段 :
名称 |
|
类型 |
说明 |
resultcode |
int |
返回码 |
|
reason |
string |
返回说明 |
|
result |
array |
返回结果集 |
|
wid |
string |
天气唯一标示符 |
|
weather |
string |
天气 |
|
error_code |
int |
错误码 |
3. 根据IP查询天气
API :juhe.apis.weather.ip (宏 :kJHAPIS_LIFE_WEATHER_IP )
返回字段同juhe.apis.weather.index(根据城市名/id查询天气)。
4. 根据GPS坐标查询天气
API :juhe.apis.weather.geo (宏 :kJHAPIS_LIFE_WEATHER_GEO)
返回字段同juhe.apis.weather.index(根据城市名/id查询天气)。
5. 城市天气三小时预报
API :juhe.apis.weather.forecast3h (宏 :kJHAPIS_LIFE_WEATHER_FORECAST3H )
返回字段 :
名称 |
|
类型 |
说明 |
resultcode |
int |
返回码 |
|
reason |
string |
返回说明 |
|
result |
array |
返回结果集 |
|
weatherid |
int |
天气标识ID |
|
weather |
string |
天气 |
|
temp1 |
string |
低温 |
|
temp2 |
string |
高温 |
|
sh |
string |
开始小时 |
|
eh |
string |
结束小时 |
|
wid |
string |
天气唯一标示符 |
|
date |
string |
日期 |
|
sfdate |
string |
完整开始时间 |
|
efdate |
string |
完整结束时间 |
|
error_code |
int |
错误码 |
6. 支持城市列表
API :juhe.apis.weather.citys (宏 :kJHAPIS_LIFE_WEATHER_CITYS )
返回字段 :
名称 |
|
类型 |
说明 |
resultcode |
int |
返回码 |
|
reason |
string |
返回说明 |
|
result |
dictionary |
返回结果集 |
|
id |
int |
城市ID |
|
province |
string |
省份名称 |
|
city |
string |
城市名称 |
|
district |
string |
城市/区名称 |
|
error_code |
int |
错误码 |
7 . 全国天气预报错误码
|
错误码 |
说明 |
|
203901 |
查询城市不能为空 |
|
203902 |
查询不到该城市的天气 |
|
203903 |
查询出错,请重试 |
|
203904 |
错误的GPS坐标 |
|
203905 |
GPS坐标解析出错,请确认提供的坐标正确(暂支持国内) |
|
203906 |
IP地址错误 |
|
203907 |
查询不到该IP地址相关的天气信息 |
5, 更多聚合数据SDK接口,访问这里: http://www.juhe.cn/juhesdk/idocs