J1ST.IO 及时云平台应用,针对iOS设备,帮助开发者搭建奇思妙想的 IoT 产品。
[待补充]
[待补充]
添加头文件
#import <J1STSDK/J1STSDK.h>
初始化SDK
从 Dev Console 获取当前 Product 的 Key ;
在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
中添加初始化代码,使用 Dev Console 获取到的 Key 替换代码中的 Key :
[J1STSDK startServiceWithProductKey:key
resultBlock:^(NSString *result, NSError *error) {
if (result) {
NSLog(@"Start success with Agent ID : %@", result);
}
else {
NSLog(@"Start failed with error : %@", error.description);
}
}];
上发数据
定义上行数据内容(J1STUpstreamData),调用上发数据API接口:
J1STUpstreamData *data = [J1STUpstreamData new];
data.deviceType = AGENT;
data.data = [NSDictionary dictionaryWithObjectsAndKeys:@"ZE16A", @"Model",
@"1.0.0", @"FwVer", nil];
[J1STSDK sendUpstreamData:data
resultBlock:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"Send Upstream Data Success");
}
else {
NSLog(@"Send Upstream Data failed with error : %@", error.description);
}
}];
接收数据
在默认消息中心添加的监听代码 :
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(onMessageReceived:)
name:kJ1STDidReceivedMessageNotification
object:nil];
添加消息处理代码 :
- (void)onMessageReceived:(NSNotification *)notification {
J1STUpstreamData *data = [notification object];
// 添加消息处理代码
……
};