TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Aug 2017 |
Maintained by jc beaudin, jc beaudin, Hugo Lefrancois, David Francoeur.
4. Installation & Configuration
iOS SDK allowing iOS apps to quickly implement the mnubo REST API.
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:
#4. Installation & Configuration
Install CocoaPods with gem install cocoapods
.
Create a file in your Xcode project called Podfile
and add the following lines:
pod 'mnuboSDK'
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.
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
}
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
}
}];
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];
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];
You can update an owner properties
[[MnuboClient sharedInstance] updateOwner:owner completion:^(NSError *error) {
if (!error) {
//Update Successful
} else {
//Update failed
}
}];
You can update a SmartObject properties
[[MnuboClient sharedInstance] updateSmartObject:smartObject withDeviceId:@"DEVICE_ID" completion:^(NSError *error) {
if (!error) {
//Update Successful
} else {
//Update failed
}
}];
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
}
}];
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.
https://github.com/mnubo/mnubo-ios-sdk/tree/master/Pod/Classes
Search function is not supported at the momment. Retry mechanism while sending events offline is not supported at the moment.