Community

Migrating Mobile Cloud client applications from the Beta

Share this post:

If you created a mobile client app that accesses Mobile Cloud services during the Beta, you’ll need to update your app. Many APIs in the Mobile Cloud Services SDK have changed. All the key asynchronous API calls now support “promises” with the use of the Bolts Framework.

Start off by getting the newest copy of the SDK for your platform. Go to the Mobile Cloud landing page. There you’ll find everything you need to get your SDK and get started.

For a broader overview of what has changed with Mobile Cloud since the beta, see our post about what’s new for June.

iOS Client SDK changes

  • Remove old SDKs from your existing projects. Add the new SDK frameworks added. Note that IBMBluemix.framework replaces IBMBaaS.framework.
  • API Changes per service:
    • IBMBluemix
      • SDK Initialization – Added applicationSecret and route. Class and method renamed.
        • Before: [IBMBaaS initializeSDK: applicationId]
        • Now: [IBMBluemix initializeApplicationId: applicationId andApplicationSecret: applicationSecret andApplicationRoute: applicationRoute]
          • Copy the applicationId, applicationSecret, and applicationRoute values from the Bluemix dashboard for your Mobile Cloud application.
      • Mobile Application Security – Class and method renamed
        • Before: [IBMBaaS setSecurityContext: securityProvider withToken: securityToken]
        • Now: [IBMBluemix setSecurityToken: securityToken fromProvider: securityProvider].
          • The call is asynchronous and requires the BFTask to report status.
    • IBMCloudCode
      • ​Service initialization – Parameter hostName removed
        • Before: [IBMCloudCode initializeService: hostName]
        • Now: [IBMCloudCode initializeService]
      • HTTP Requests – All IBMCloudCode calls removed the IBMHttpRequestDelegate parameter and added a return type of BFTask with a IBMHttpResponse result. These calls are asynchronous and provides the result of the HTTP request with a Bolts BFTask. For example,
        • Before: [IBMCloudCode get: uri, withDelegate: delegate]
        • Now: [IBMCloudCode get: uri] returns BFTask with a IBMHttpResponse result.
    • IBMData
      • ​Saving an Object – No longer uses callback, instead returns a BFTask
        • ​Before: [item saveInBackgroundWithCallback: <Block>];
        • Now: [item save] that returns the object on success in the result of the BFTask
      • Finding Objects – No longer uses callback, instead returns a BFTask
        • ​Before: [query findObjectsInBackgroundWithBlock: <block>];
        • Now: [query find]; that returns an NSArray* of objects in the result of the BFTask
      • Updating an Object – No longer uses callback, instead returns a BFTask
        • ​Before: [item saveInBackgroundWithCallback:<block>];
        • Now: [item save]; that returns the object on success in the result of the BFTask
      • Deleting an Object – No longer uses callback, instead returns a BFTask
        • ​Before: [item deleteInBackgroundwithCallback:<block>];
        • Now: [item delete]; that returns a BFTask which allows you to handle the error or success path
      • Creating IBMDataClientManager parameters
        • ​Before: [parameters setObject: CL_LIVE_SYNC_ENABLE_KEY forKey: [NSNumber numberWithBool: YES]];
        • Now: [parameters setObject: IBMFileLiveSyncEnableKey forKey: [NSNumber numberWithBool: YES]];
      • Initializing the Client Manager
        • ​Before: [clientManager connect: parameters success: <block> failure: <block>];
        • Now: [clientManager connect: parameters]; that returns a BFTask which allows you to handle the error or success path
      • Synchronizing files
        • ​Before: [syncedFiles sync:<block> failure: <block>];
        • Now: [synchedFiles sync]; that returns a BFTask which allows you to handle the error or success path
      • Upload/Save a file
        • ​Before: [file upload:<block> failure: block];
        • Now: [file save]; that returns a BFTask which allows you to handle the error or success path
      • Download/Fetch a file
        • ​Before: [file download: IBMDataFileRequestReturnCachedIfExists success:<block> notFound:<block> failure:<block>];
        • After: [file fetch: IBMDataFileRequestReturnCachedIfExists]; that returns a BFTask which allows you to handle an error (404 or other) or success path​
    • IBMPush
      • Register Device – No longer uses IBMPushResponseDelegate, instead returns a BFTask.
        • Before: [push registerDevice:@“alias” withConsumerId:@“consumerId” withDeviceToken@“token” withDelegate:@“pDelegate”]
        • Now: [push registerDevice:@“alias” withConsumerId:@“consumerId” withDeviceToken:@token”] that returns a BFTask which gets you the deviceId on success or handle the error on failure
      • Subscribe to Tag – No longer uses IBMPushResponseDelegate, instead returns a BFTask.
        • Before: [push subscribeToTag:@“tag” withDelegate@“pDelegate]
        • Now: [push subscribeToTag:@tag”] returns a BFTask that has the subscribed tag name on success or handle the error on failure
      • Unsubscribe from Tag – No longer uses IBMPushResponseDelegate, instead returns a BFTask.
        • Before: [push unsubscribeFromTag:@“tag” withDelegate:@“pDelegate”]
        • Now: [push unsubscribeFromTag:@“tag”] returns a BFTask that has the unsubscribed tag name on success or handle the error on failure
      • Get tags – No longer uses IBMPushResponseDelegate, instead returns a BFTask.
        • Before: [push getTagsUsingDelegate:@“pDelegate”]
        • Now: [push getTags] returns a BFTask that has the list of available tag names on success or handle the error on failure
      • Get subscriptions – No longer uses IBMPushResponseDelegate, instead returns a BFTask.
        • Before: [push getSubscriptionsUsingDelegate:@“pDelegate”]
        • Now: [push getSubscriptions] returns a BFTask that has the list of subscribed tags on success or handle the error on failure.

Android Client SDK changes

  • Remove old SDKs from your existing project and add the new SDK frameworks. Note that ibmbluemix.jar replaces ibmbaas.jar.
  • API Changes per service:
    • IBMBluemix
      • SDK Initialization – Added applicationSecret and route. Class and method renamed.
        • Before: IBMBaaS.initializeSDK(applicationId)
        • Now: IBMBluemix.initialize(context, applicationId, applicationSecret, applicationRoute)
          Copy the applicationId, applicationSecret, and applicationRoute values from the Bluemix dashboard for your Mobile Cloud application.
      • Mobile Application Security – Class and method renamed
        • Before: IBMBaaS.setSecurityContext(securityProvider, securityToken) is now
        • Now: IBMBluemix.setSecurityToken(securityProvider, securityToken).
          • Returns a Task<IBMCurrentUser>. The call is asynchronous and requires the Task to report status.
    • IBMCloudCode
      • ​Service initialization – hostName parameter removed
        • ​Before: IBMCloudCode.initializeService(hostName)
        • Now: IBMCloudCode initializeService()
      • HTTP Requests – all IBMCloudCode calls removed the IBMHttpRequestDelegate parameter and added a return type of Task<IBMHttpResponse>. These calls are asynchronous and provide the result of the HTTP request with a Bolts Task<IBMHttpResponse>. For example,
        • Before: IBMCloudCode.get(uri, delegate)
        • Now: IBMCloudCode.get(uri) returns Task<IBMHttpResponse> with the result.
    • IBMData
      • Saving an Object – No longer uses callback, instead returns a BFTask
        • ​Before: item.saveInBackground( new IBMObjectResult<Item>() { … });
        • Now: item.save() that returns the object on success in the result of the BFTask
      • Finding Objects – No longer uses callback, instead returns a BFTask
        • ​Before: query.findObjectsInBackground(new IBMObjectResult<Item>() { … });
        • Now: query.find(); that returns an List<Item> of objects in the result of the BFTask
      • Updating an Object – No longer uses callback, instead returns a BFTask
        • ​Before: item.saveInBackground( new IBMObjectResult<Item>() { … });
        • Now: item.save() that returns the object on success in the result of the BFTask
      • Deleting an Object – No longer uses callback, instead returns a BFTask
        • ​Before: item.deleteInBackground( new IBMObjectResult<Item>() { … });
        • Now: item. delete(); that returns a BFTask which allows you to handle the error or success path
      • Creating IBMDataClientManager parameters
        • ​Before: parameters.put(CL_LIVE_SYNC_ENABLE_KEY, Boolean.TRUE);
        • Now: parameters.puth(IBMFileLiveSyncEnableKey, Boolean.TRUE);
      • Initializing the Client Manager
        • ​Before: clientManager.connect(parameters, new IBMDataClientManager.IBMDataClientManagerConnectionCallback() {….});
        • Now: clientManager.connect(parameters, null); that returns a BFTask with an IBMDataClientManger
      • Upload/Save a file
        • ​Before: file.upload( new IBMDataFile.IBMDataFileCallback() {….}));
        • Now: file.save(); that returns a BFTask with and IBMDataFile
      • Download/Fetch a file
        • ​Before: file.download(IBMDataFileRequestReturnCachedIfExists, new IBMDataFile.IBMDataFileCallback() {….});
        • After: file.fetch(IBMDataFileRequestReturnCachedIfExists); that returns a BFTask which allows you to handle an error or success path​
    • IBMPush
      • Register Device – No longer uses IBMPushResponseListener, instead returns a Task
        • Before: push.registerDevice(“CustomerId”, “Alias”, new IBMPushResponseListener<String> ( ) { … });
        • Now: push.registerDevice(“CustomerId”, “Alias”) that returns the deviceId on success, in the result of Task<String>
      • Subscribe to Tag – No longer uses IBMPushResponseListener, instead returns a Task
        • Before : push.subscribe(“tagName”, new IBMPushResponseListener<String> ( ) { … });
        • Now : push.subscribe(“tagName”) that returns the subscribed tag name on success, in the result of Task<String>
      • Unsubscribe from Tag – No longer uses IBMPushResponseListener, instead returns a Task
        • Before : push.unsubscribe(“tagName”, new IBMPushResponseListener<String> ( ) { … });
        • Now : push.unsubscribe(“tagName”) that returns the unsubscribed tag on success, in the result of Task<String>
      • Get tags – No longer uses IBMPushResponseListener, instead returns a Task
        • Before : push.getTags( new IBMPushResponseListener <List <String>> ( ) { … });
        • Now : push.getTags( ) that returns a list of tags on success, in the result of Task <List <String>>
      • Get Subscriptions – No longer uses IBMPushResponseListener, instead returns a Task
        • Before : push.getSubscriptions( new IBMPushResponseListener <List <String>> ( ) { … });
        • Now : push.getSubscriptions( ) that returns a list of subscribed tags on success, in the result of Task <List <String>>
      • The listen( ) method continues to use IBMPushNotificationListener as the parameter whose onRecieve( ) method is called when a push message is received.

JavaScript SDK changes

  • Remove the old SDKs from your projects. You can remove them from your packages.json or bower.json files and manually delete your node_modules and bower www/components directories. Or, you can use npm uninstall or bower prune commands to remove them using the command line tools.
  • Include the new packages in your projects. For accessing the code directly from DevOps, use the following dependency lists. These lists work for Bower type dependencies. At this point in time, Bower does not support none git: protocols.[code]dependencies:{
    ‘ibmbluemix’:’git+https://hub.jazz.net/git/bluemixmobilesdk/ibmbluemix-javascript’,
    ‘ibmpush’: ‘git+https://hub.jazz.net/git/bluemixmobilesdk/ibmpush-javascript’,
    ‘ibmcloudcode’: ‘git+https://hub.jazz.net/git/bluemixmobilesdk/ibmcloudcode-javascript’,
    ‘ibmdata’: ‘git+https://hub.jazz.net/git/bluemixmobilesdk/ibmcloudcode-javascript’
    }[/code]

    You can use the same Bower style dependencies in Node package.json to access DevOps code, but we recommend using the NPM published versions. You can use the short NPM reference names:

    [code]dependencies:{
    ‘ibmbluemix’:’*’,
    ‘ibmpush’: ‘*’,
    ‘ibmcloudcode’: ‘*’,
    ‘ibmdata’: ‘*’
    }[/code]

  • API Changes per service:
    • IBMBluemix
      • SDK Initialization – Added applicationSecret and route. Class and method renamed.
        • Before: IBMBaaS.initializeSDK( applicationId,applicationRoute);
        • Now: IBMBluemix.initialize({applicationId:”…”,applicationSecret:”…”,applicationRoute:”…});
        • Copy the applicationId, applicationSecret, and applicationRoute values from the Bluemix dashboard for your Mobile Cloud application.
      • MAS Security – Class and method renamed
        • Before: IBMBaaS.setSecurityContex(securityProvider, securityToken);
        • Now: IBMBluemix.setSecurityToken(securityToken, securityProvider);.
          • The call is asynchronous and returns a promise.
        • There are new APIs for returning IBMBluemix.getCurrentUser() and IBMBluemix.getCurrentDevice() after successful call of setSecurityToken
    • IBMCloudCode
      • ​Service Initialization – Parameter hostName removed
        • Before: IBMCloudCode.initializeService(hostName);
        • Now: IBMCloudCode.initializeService();

Mobile Cloud Node.js template

The cloud code template now uses the Express V4.x web application framework and the new Router API, so that your REST endpoints can be modularized and scalable. To rewrite your REST endpoints based on the new structure of the cloud code template, you might:

    1. Create a people.js file and put it in the lib folder.
    2. Open the people.js file and write a mini express app with the Router API: [code]var people = require(‘express’).Router();
      people.get(‘/’, function(req, res, next) {
      });
      people.post(‘/’, function(req, res, next) {
      });
      people.put(‘/’, function(req, res, next) {
      });
      people.delete(‘/’, function(req, res, next) {
      });
      module.exports = exports = people;[/code]

  1. Map the mini express app you have just created to the cloud code context root in the app.js file: [code]app.use(ibmconfig.getContextRoot(), require(‘./lib/people.js’)); [/code]

For more information about the template, see the DevOps repository: https://hub.jazz.net/project/bluemixmobilesdk/ibmcloudcodetemplate/

More stories
February 13, 2019

Simplify and Automate Deployments Using GitOps with IBM Multicloud Manager 3.1.2

Use Argo CD, a GitOps continuous delivery tool for Kubernetes, and IBM Multicloud Manager to achieve declarative and automated deployment of applications to multiple Kubernetes clusters.

Continue reading

February 11, 2019

Solving Business Problems with Splunk on IBM Cloud Kubernetes Service

In this tutorial, we will install Splunk Connect for Kubernetes into an existing Splunk instance. Splunk Connect for Kubernetes provides a way to import and search your Kubernetes logging, object, and metrics data in Splunk.

Continue reading

February 8, 2019

A How-To for Migrating Redis to IBM Cloud Databases for Redis

If you’re moving your data over to IBM Cloud Databases for Redis, you’ll need to take some steps to successfully migrate all of your data. We’ve got you covered. In this post, we’ll show you a quick way to start migrating your data across to Databases for Redis, whether your database is on-premise or in the cloud.

Continue reading