测试已测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
发布上次发布 | 2017年8月 |
由 jc beaudin,jc beaudin,Hugo Lefrancois,David Francoeur 维护。
iOS SDK 允许 iOS 应用快速实现 mnubo REST API。
SDK 的主类必须使用您的 mnubo 账户信息(客户端 ID 和主机名)进行初始化。以上功能都从此类中可用。
SDK 管理
sharedInstanceWithClientId:andHostname
sharedInstance
身份验证
logInWithUsername:password:completion
logInWithUsername:andToken:completion
logout
isOwnerConnected
服务
updateSmartObject:withDeviceId:completion
createSmartObject:withDeviceId:withObjectType:completion
deleteSmartObjectWithDeviceId:completion
updateOwner:completion
createOwner:withPassword:completion
deleteOwner:completion
sendEvents:withDeviceId:completion
使用 `gem install cocoapods` 命令安装 CocoaPods。
在您的 Xcode 项目中创建一个名为 `Podfile` 的文件,并添加以下行
pod 'mnuboSDK'
在您的 xcode 项目目录中运行 `pod install`。CocoaPods 应该下载并安装 mnubo iOS SDK,并创建一个新的 Xcode 工作空间。在 Xcode 中打开此工作空间。
我们建议在您的应用程序中使用 mnubo SDK 的共享实例,并在您的应用程序的AppDelegate中如下初始化SDK:
#import <mnuboSDK/MnuboClient.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[MnuboClient sharedInstanceWithClientId:@"CLIENT_ID" andHostname:@"BASE_URL"];
return YES
}
当用户已存在于 mnubo SmartObjects 平台上时,可以执行身份验证以获取用户的访问令牌。此登录方法需要用户的用户名和密码进行身份验证。
[[MnuboClient sharedInstance] loginWithUsername:@"USERNAME" password:@"PASSWORD" completion:^(NSError *error)
{
if (!error) {
// The owner is connected and can now use the app
} else {
// An error occured while login the owner
}
}];
您可以在任何时候验证所有者是否已连接。只需使用 isOwnerConnected 方法获取一个布尔值。
// YES if the owner is connected and NO if the owner is not currently connected
BOOL isOwnerConnected = [[MnuboClient sharedInstance] isOwnerConnected];
当需要登出所有者时,logout 方法将清除所有者的所有访问令牌。在此操作之后,isOwnerConnected 方法将返回“否”(false)。您的应用受限制部分应不可访问。
// Log the owner out and clear all the tokens
[[MnuboClient sharedInstance] logout];
您可以更新所有者的属性。
[[MnuboClient sharedInstance] updateOwner:owner completion:^(NSError *error) {
if (!error) {
//Update Successful
} else {
//Update failed
}
}];
您可以更新 SmartObject 的属性。
[[MnuboClient sharedInstance] updateSmartObject:smartObject withDeviceId:@"DEVICE_ID" completion:^(NSError *error) {
if (!error) {
//Update Successful
} else {
//Update failed
}
}];
您可以在任何时候发送自定义事件。
MNUEvent *event = [[MNUEvent alloc] init];
event.eventType = @"EVENT_TYPE";
[event setTimeseries: @{ @"KEY": @"VALUE"}];
// Send the event to the mnubo SmartObjects platform by specifying the device_id
[[MnuboClient sharedInstance] sendEvents:@[event] withDeviceId:@"DEVICE_ID" completion:^(NSError *error) {
if (!error) {
//Send Successful
} else {
//Send failed
}
}];
请记住监听 com.mnubo.sdk.login.expired
通知。如果在尝试续订令牌时认证失败,将发送此通知。对此通知的响应应是将用户返回到登录视图。
https://github.com/mnubo/mnubo-ios-sdk/tree/master/Pod/Classes
目前不支持搜索功能。目前不支持发送事件过程中的重试机制。