mnuboSDK 2.0.1

mnuboSDK 2.0.1

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Aug 2017

Maintained by jc beaudin, jc beaudin, Hugo Lefrancois, David Francoeur.



mnuboSDK 2.0.1

  • By
  • mnubo, Inc

mnubo iOS SDK

Table of Content

1. Introduction

2. Architecture

3. Pre-requisites

4. Installation & Configuration

5. Usage

6. Important notes

7. Source code

8. Known limitations

9. References


#1. Introduction

iOS SDK allowing iOS apps to quickly implement the mnubo REST API.


#2. Architecture

mnubo

The primary class of the SDK has to be initialized with your mnubo account informations (client id and hostname ). The functions above are available from this class.

  • SDK Management

    • sharedInstanceWithClientId:andHostname:
    • sharedInstance
  • Authentication

    • logInWithUsername:password:completion:
    • logInWithUsername:andToken:completion:
    • logout
    • isOwnerConnected
  • Services

    • updateSmartObject:withDeviceId:completion:
    • createSmartObject:withDeviceId:withObjectType:completion:
    • deleteSmartObjectWithDeviceId:completion:
    • updateOwner:completion:
    • createOwner:withPassword:completion:
    • deleteOwner:completion:
    • sendEvents:withDeviceId:completion:

#3. Pre-requisites

  • CocoaPods
  • iOS

#4. Installation & Configuration

  1. Install CocoaPods with gem install cocoapods.

  2. Create a file in your Xcode project called Podfile and add the following lines:

    pod 'mnuboSDK'
  3. Run pod install in your xcode project directory. CocoaPods should download and install the mnubo iOS SDK, and create a new Xcode workspace. Open up this workspace in Xcode.


#5. Usage

Initialize the MnuboClient

We recommend to use the shared instance of the mnubo SDK in your application and should initialize the SDK as follows in your app delegate:

#import <mnuboSDK/MnuboClient.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

  [MnuboClient sharedInstanceWithClientId:@"CLIENT_ID" andHostname:@"BASE_URL"];

  return YES
}

Log In an owner

Once an owner is present in the mnubo SmartObjects platform, an authentication can be executed to fetch the owner's access tokens. This login method requires the username and the password of the owner to authenticate.

[[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
  }
}];

Check if an owner is connected

At anytime you can validate if an owner is connected. Simply retrieve a boolean with the help of the isOwnerConnected method.

// YES if the owner is connected and NO if the owner is not currently connected
BOOL isOwnerConnected = [[MnuboClient sharedInstance] isOwnerConnected];

Log Out an owner

When the owner needs to be logged out, the logout method will clear all of the owner's access tokens. After that operation, the isOwnerConnected method will return NO (false). Access to restricted section of your app should be made unavailable.

// Log the owner out and clear all the tokens
[[MnuboClient sharedInstance] logout];

Update Owner

You can update an owner properties

[[MnuboClient sharedInstance] updateOwner:owner completion:^(NSError *error) {
    if (!error) {
        //Update Successful
    } else {
        //Update failed
    }
}];

Update SmartObject

You can update a SmartObject properties

[[MnuboClient sharedInstance] updateSmartObject:smartObject withDeviceId:@"DEVICE_ID" completion:^(NSError *error) {
    if (!error) {
        //Update Successful
    } else {
        //Update failed
    }
}];

Send Events

At anytime, you can send custom events.

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. Important notes

Do not forget to listen for the com.mnubo.sdk.login.expired notification. This notification will be sent in case the authentication is not able to renew its token. The response to this notification should be to take the user back to the login view.


#7. Source code

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


#8. Known limitations

Search function is not supported at the momment. Retry mechanism while sending events offline is not supported at the moment.


#9. References

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