第一步:将 SDK 导入到你的工程中第二步:引入头文件和注册 SDK 的 AppID- 登录机智云官方网站查看产品信息获得 AppID 。
- 初始化 SDK
打开 *AppDelegate.m(*代表你的工程名字) 导入文件头 #import <GizDataAccess/GizDataAccess.h>在 - (BOOL)application:didFinishLaunchingWithOptions:方法中调用 startWithAppID 方法来初始化 SDK,指定APPID. - (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions { //Init SDK [GizDataAccess startWithAppID“APP_ID”]; // …… return YES;}第三步:用户登录如下 GizDataAccessLogin* gdaLogin = [[GizDataAccessLogin alloc] initWithDelegate:YOUR_LOGIN_DELEGATE]; 如下 - (void)gizDataAccessDidLoginGizDataAccessLogin *)login uidNSString *)uid tokenNSString *)token resultGizDataAccessErrorCode)result messageNSString *)message { if(result == kGizDataAccessErrorNone) { // 登录成功 // …… } else { // 登录失败 // …… }}如下 [gdaLogin loginAnonymous]; 第四步:数据接入如下 GizDataAccessSource* gdaSource = [[GizDataAccessSource alloc] initWithDelegate:YOUR_DATAACCESS_DELEGATE]; 数据上传如下 - (void)gizDataAccessDidSaveDataGizDataAccessSource *)source resultGizDataAccessErrorCode)result messageNSString *)message { if(result == kGizDataAccessErrorNone) { // 数据上传成功 // …… }}如下 [gdaSource saveData“YOUR_LOGIN_TOKEN” productKey“YOUR_BT_PRODUCT_KEY” deviceSN“YOUR_BT_DEVICE_SN” timestampATA_TIMESTAMP attributes“YOUR_DATA”]; 获取数据实现 获取数据的委托方法 获取到的数据内容,按以下键值对方式提供: @"attrs" : { [dynamic_keys] : [dynamic_values], ... }, @"uid" : [uid], @"sn" : [sn], @"ts" : [ts], @"product_key" : [product_key]
如下 - (void)gizDataAccessDidLoadData:(GizDataAccessSource *)source data:(NSArray *)data result:(GizDataAccessErrorCode)result errorMessage:(NSString *)message { if(result == kGizDataAccessErrorNone) { // 获取数据成功 for(NSDictionary *dict in data) { NSString* sn = [dict valueForKey"device_sn"]; NSString* productkey = [dict valueForKey"product_key"]; NSString* uid = [dict valueForKey"uid"]; NSNumber *nTS = [dict valueForKey"ts"]; NSDictionary* attributes = [dict valueForKey"attrs"]; NSLog(@"sn:%@ productkey:%@ uid:%@ nTS:%@ attributes:%@", sn, productkey, uid, nTS, attributes); } }}如下 [gdaSource loadData:@“YOUR_LOGIN_TOKEN” productKey:@“YOUR_BT_PRODUCT_KEY” deviceSN:@“YOUR_BT_DEVICE_SN” startTime:START_DATA_TIME endTime:END_DATA_TIME limit:20 skip:0]; Error codescode | message | 0 | success | 9002 | product_key invalid | 9003 | appid invalid | 9004 | token invalid | 9006 | token expired | 9008 | server error | 9015 | form invalid | 9999 | reserved |
|