mnuboSDK 2.0.1

mnuboSDK 2.0.1

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布上次发布2017年8月

jc beaudinjc beaudinHugo LefrancoisDavid Francoeur 维护。



mnuboSDK 2.0.1

  • mnubo, Inc

mnubo iOS SDK

目录

1. 简介

2. 架构

3. 先决条件

4. 安装和配置

5. 使用方法

6. 重要注意事项

7. 源代码

8. 已知限制

9. 参考


#1. 简介

iOS SDK 允许 iOS 应用快速实现 mnubo REST API。


#2. 架构

mnubo

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

#3. 先决条件

  • CocoaPods
  • iOS

#4. 安装和配置

  1. 使用 `gem install cocoapods` 命令安装 CocoaPods

  2. 在您的 Xcode 项目中创建一个名为 `Podfile` 的文件,并添加以下行

    pod 'mnuboSDK'
  3. 在您的 xcode 项目目录中运行 `pod install`。CocoaPods 应该下载并安装 mnubo iOS SDK,并创建一个新的 Xcode 工作空间。在 Xcode 中打开此工作空间。


#5. 使用方法

初始化 MnuboClient

我们建议在您的应用程序中使用 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

您可以更新 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
    }
}];


#6. 重要注意事项

请记住监听 com.mnubo.sdk.login.expired 通知。如果在尝试续订令牌时认证失败,将发送此通知。对此通知的响应应是将用户返回到登录视图。


#7. 源代码

https://github.com/mnubo/mnubo-ios-sdk/tree/master/Pod/Classes


#8. 已知限制

目前不支持搜索功能。目前不支持发送事件过程中的重试机制。


#9. 参考文献

https://en.wikipedia.org/wiki/IOS_SDK