获取带有Objective C / iPhone的城市列表
使用Objective C / iPhone获取指定国家/地区的城市列表
Objective C / iPhone : API文档
获取带有Objective C / iPhone的城市列表
NSString *aclass = @"country";
NSString *method = @"getcities";
NSString *user = @"user";
NSString *password = @"password";
NSString *countrycode = @"us";
NSString *targetUrl = [NSString stringWithFormat:@"https://www.afilnet.com/api/http/?class=%@&method=%@&user=%@&password=%@&countrycode=%@", aclass, method, user, password, countrycode]
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setHTTPMethod:@"GET"];
[request setURL:[NSURL URLWithString:targetUrl]];
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:
^(NSData * _Nullable data,NSURLResponse * _Nullable response,NSError * _Nullable error) {
NSString *myString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Data received: %@", myString);
}] resume];
参数 | 描述 | 必修/可选 |
---|---|---|
class=country | 要求的课程:要求的课程 | 必修 |
method=getcities | 请求的类方法:发出请求的类的方法 | 必修 |
user | 您的Afilnet帐户的用户和电子邮件 | 必修 |
password | 您的Afilnet帐户的密码 | 必修 |
countrycode | ISO国家/地区代码,采用ISO-3166-1 ALPHA-2格式 | 必修 |
发出请求时,您将收到以下字段:
- status
-
结果(如果status = success),您将在此处收到以下值:
- 没有其他值会发送给您
- 错误(如果status = error),在这里您将收到错误代码
下面列出了可能的错误代码
码 | 描述 |
---|---|
MISSING_USER | 不包括用户或电子邮件 |
MISSING_PASSWORD | 不包含密码 |
MISSING_CLASS | 不包括课程 |
MISSING_METHOD | 不包括方法 |
MISSING_COMPULSORY_PARAM | 不包括强制参数 |
INCORRECT_USER_PASSWORD | 用户或密码错误 |
INCORRECT_CLASS | 班级不正确 |
INCORRECT_METHOD | 方法不正确 |
EMPTY_COUNTRYCODE | 国家区号为空 |
COUNTRY_NOT_FOUND | 没有指定密码的国家/地区 |
参数:
- class : country
- method : getcities
- user : user
- password : password
- countrycode : us
请求:
https://www.afilnet.com/api/http/?class=country&method=getcities&user=user&password=password&countrycode=us