Smartface Developer Center

Smartface Developer Center

Welcome to the Smartface Developer Hub. You'll find comprehensive guides and documentation to help you start developing and managing native iOS and Android apps with Smartface Cloud.

Get Started    

Oracle Mobile Cloud Enterprise (formerly Oracle MCS)

What is Oracle MCE (MCS)?

Oracle Mobile Cloud Service (Oracle MCS) is an enterprise mobile backend service. Unlike other cloud offerings, MCS is focused not only on providing enterprise quality Mobile Backend as a Service (MBaaS), but also providing easy to use tools for business professionals to analyze and mine data about the usage of the MBaaS.

Which APIs does MCS Provide?

To simplify mobile app development, Mobile Cloud Service provides these built-in APIs:

  • Push Notifications
  • Mobile User Management and Authentication
  • Analytics
  • Mobile Storage
  • Device Management

You can read more at this link.

Using Smartface and Oracle MCS, you can develop native iOS and Android apps with cloud features just with JavaScript knowledge.

What is Smartface Oracle MCS JavaScript Extension?

The extension utilizes the REST API provided by Oracle MCS. It provides easy access to Oracle MCS endpoints for developers.

These functions are made specifically to integrate Oracle MCS to your apps easily and quickly in JavaScript.

  • Authentication
      MCS supports anonymous authentication. Anonymous login information is provided, every transaction will be over this anonymous user information.
      login - authenticate User and password based authentication against Oracle MCS Mobile User Management.
      logout - clears user login information. Uses anonymous user information if provided with the MCS setup

  • Analytics
      sendBasicEvent - to send basic analytics events to the analytics module.
      sendAnalytic - to send complex analytics events to the analytics module.

  • Storage
      getCollectionList - Get the of all storage collections
      getItemListInCollection - Get item list in a storage collection
      getItem - Get encoded item data
      storeItem - Upload item to a collection
      deleteItem - Delete item from a collection

  • Push Notifications
      registerDeviceToken - Register device push notification token
      deregisterDeviceToken - Deregister device push notification token

  • App Policies
    getAppPolicies - Get application policies from MCS

  • Location (ble beacon related)
      getDeviceLocationsByName - Get Device Location List by Name
      getDeviceLocationsById - Get Device Location List by ID
      getPlaceByName - Get Places List by Name
      getPlaceById - Get Places List by ID
      getAssetByName - Get Asset List by Name
      getAssetById - Get Asset List by ID

  • Custom APIs
      createRequestOptions - Creates a HTTP Request params Object to call custom API's easily

Usage Examples

To demonstrate lib usage we will go through following steps;

App Start
Login (if Authenticated)
------------Register for Push notifications
------------------------Register against Google GCM / Firebase and Apple APNS
------------------------Register against Oracle MCS
------------Get Storage Objects
------------------------Get Collection (if success)
------------------------------------Get Collection Objects (if success)
------------------------------------------------Get Object
------------------------------------------------Delete Object
------------------------------------------------Upload a File
------------Get logged in user data.

Please note that this guide does not provide details on the application UI implementations in our samples. You can refer to the related guides from the left navigation.

Installation

MCS Extension can be installed via npm from our public npm repository. The installation is pretty easy in the Smartface Cloud IDE.

  1. Open terminal (F6 for Windows; Ctrl + Esc for Mac)
  2. Type the install script below to terminal
  3. Finally require the extension as: require("sf-extension-mcs")
cd ~/workspace/scripts
npm i -S sf-extension-mcs

Code Samples

1 - Init your MCS config

const MCS = require('sf-extension-mcs');
var options = {
	'backendId': 'YOUR BACKEND ID', //required
	'baseUrl': 'YOUR BASE URL', //required
	'androidApplicationKey': 'YOUR ANDROID APP KEY', //required only for analytics & events
	'iOSApplicationKey': 'YOUR IOS APP KEY', //required only for analytics & events
	'anonymousKey': 'YOUR BASIC AUTHENTICATION ANONYMOUS KEY' //required only to perform operations without logging in first
};
var mcs = new MCS(options);

2 - Login to MCS

mcs.login({
	'username': 'YOUR USER NAME',
	'password': 'YOUR PASSWORD'
},

function(err, result) {

	loadingView.visible = false;

	if (err) {
		return alert("LOGIN FAILED.  " + err);
	}

	alert("LOGIN SUCCESS.  " + result);	

);

3 - Register for push notifications

Please refer to this document for requirements. This method is calling registerForPushNotifications inside.

var optionsRegisterDevice = {
    packageName: Application.packageName,
    version: Application.version,
};

mcs.registerDeviceToken(optionsRegisterDevice, function(err, result) {

    if (err) {
        return alert("registerDeviceToken FAILED.  " + err);
    }

    alert("registerDeviceToken SUCCESS.  " + result.toString());

});

4 - Send Basic Analytics Event

var optionsAnalytic = {
    'deviceID': '112233', //you may need to generate this by your own and store to reuse
    'sessionID': '112233', //you may need to generate this by your own
    'eventName': 'sendBasicEvent'
};

mcs.sendBasicEvent(optionsAnalytic, function(err, result) {

    if (err) {
        return alert("sendBasicEvent FAILED.  " + err);
    }

    alert("sendBasicEvent SUCCESS.  " + result.toString());

});

5 - Get Application Policies

mcs.getAppPolicies(function(err, result) {

    if (err) {
        return alert("registerDeviceToken FAILED.  " + err);
    }

    alert("registerDeviceToken SUCCESS.  " + result.toString());

});

6 - Get Item List in Collection

mcs.getCollectionList(

    function(err, result) {

        if (err) {
            return alert("getCollectionList FAILED.  " + err);
        }

        CollectionID = result[0].id;
        MCS.getItemListInCollection(CollectionID, function(err, result) {

                if (err) {
                    return alert("getItemListInCollection FAILED.  " + err);
                }

                alert("getItemListInCollection SUCCESS. " + JSON.stringfy(result));

            }

        );
    }
);

7 - Upload Item to Collection

Multimedia.pickFromGallery({
    type: Multimedia.Type.IMAGE,
    onSuccess: onSuccess,
    page: self
});

function onSuccess(picked) {

    var pickedImage = picked.image;
    var imageBlob = pickedImage.compress(Image.Format.JPEG, 100);
    var base64TestImageData = imageBlob.toBase64();

    var random_number = getRandomArbitrary(1000000000, 9999999999);

    mcs.storeItem({
            'collectionId': CollectionID,
            'itemName': 'testFile_' + random_number + '.png',
            'base64EncodeData': base64TestImageData,
            'contentType': 'image/png'
        },
        function(err, result) { // e array dönüyor. collection name leri

            if (err) {
                return alert("storeItem FAILED.  " + err);
            }

            alert("File Upload Success : " + 'testFile_' + random_number + '.png');
        }
    );

}

8 - Delete Item in Collection

mcs.deleteItem ({
    'collectionId': CollectionID,
    'itemId':  ItemID'
 		},
    function(err, result) { // e array dönüyor. collection name leri

      if (err) {
        return alert("deleteItem FAILED.  " + err);
      }

      alert("deleteItem SUCCESS. " + result);
    }
 );

How to send Push Notifications through MCS

To send push notifications through MCS, it is necessary to register with the embedded token. First, register the device by going through the steps above.

Sending notifications through MCS is as easy as any other cloud messaging/push notification service. Android and iOS JSON structures should be as follows:

Android Push Notifications:

{
      "body" : "yourbody",
      "title" : "yourtitle",
      "icon" : "youricon",
      "channelId": "50",
      "channelIdTitle": "Smartface",
      "channelIdImportance": "4",
      "customKey" : "customeValue"
}

iOS Push Notifications:

{
  "aps": {
    "alert": "body",
    "data": {
      "customKey": "customeValue"
    }
  }
}

Extension Source Code

The full source code of this extension is available on Github.

https://github.com/smartface/sf-extension-mcs

More