ThingSmart SDK 5.2 Version Update
In the 5.2 version of the ThingSmart SDK, we've introduced a feature to fetch the list of countries. This allows developers to acquire a comprehensive list of countries during login or registration.
Here's how to implement it:
Fetching the Country List
Invoke the following method to successfully fetch the country list:
```objc
[[ThingSmartUser sharedInstance] countryListWithSuccess:^(NSArray<ThingSmartCountryModel *> * _Nonnull list) {
...
} failure:^(NSError *error) {
...
}];
```
In this method, the `success` callback function returns an array of `ThingSmartCountryModel`, where each element represents a country.
ThingSmartCountryModel
This model defines the basic information of a country:
```objc
@interface ThingSmartCountryModel : NSObject
@property (nonatomic, strong) NSString *countryCode;//Country code
@property (nonatomic, strong) NSString *countryAbb;//Country abbreviation
@property (nonatomic, strong) NSString *countryName;//Country name
@property (nonatomic, strong) NSString *firstLetter;//First letter of the country name
@end
```
Implementation for Earlier SDK Versions
For earlier versions of the SDK, you can fetch the country list in the following way:
```objc
[[[TuyaSmartRequest alloc]init] requestWithApiName:@"tuya.m.country.list" postData:nil getData:nil version:@"1.0" success:^(id result) {
NSLog(@"%@",result);
} failure:^(NSError *error) {
}];
```
This method calls back a result, which includes the following fields:
- `p` : Country abbreviation
- `n` : Country name
- `c` : Country code
- `a` : First letter of the country name
Example:
```json
{
"p" : "afghanistan",
"n" : "Afghanistan",
"c" : "93",
"a" : "AF"
}
```