Tag Archives: android

Adaptive mobile apps that change based on personal context

That title get your attention?  Yes, it really read “Adaptive mobile apps that change based on personal context” – with near real-time rules application, without much extra development effort.  If that sounds interesting to you, or like a product you might want to use within your own apps, then you might want to check out this site where you can get involved in the product’s development: http://adaptiveexperience.mybluemix.net/

IBM is looking for your input on creating these types of mobile app experiences. User experiences within a single app that can be dramatically different per user based on location, past behavior, profile information, social media activity, and so much more.  With this behavior being driven by configurable rules that can be changed without redeploying an app to the app store.

How it works for your customer

Consider this scenario:

Jon and Andrea download the mobile app for S&W, a retailer known for its attention to providing great customer service. Over the next month, Jon and Andrea use the app to browse and discover content and merchandise differently.

Jon primarily navigates to sports related content for his favorite teams to find gear and clothes for travel to his favorite team’s games. Andrea scours the app for sales and fashion trends and usually ends up following her favorite designers.

Andrea and Jon go to a baseball game together. She’s never enjoyed watching it, so she opens up the S&W app to entertain herself, and her app’s navigation quickly steers her through Spring fashion articles.

Jon however, wants to replace the hat he’s worn the last three times the team lost, and since he’s in the stadium, his S&W app opens right up to the team’s gear page. The app knows he’s out of town and tells him how to get to an S&W store.

How it works for the dev team

Consider another scenario:

One of the developers on the team, George, sets up the system and application. He then gives access to Janet who is responsible for the customer experience.

Janet writes rules defining how the application could adapt and become more personalized based on inputs like , social media, geolocation, app usage, or customer information data.

Once Janet has built out her rules, she simply hits ‘Submit’ and can immediately see her clever interactions reflected in the mobile application without having to involve the development team.

Analytics let Janet know which adaptations are working best, and helps her find new opportunities to optimize the app’s user experience.

Sound interesting yet?  Check it out, and get involved in the product development at:  http://adaptiveexperience.mybluemix.net/

We’re not talking about a content management system, or translation based on locale, instead a rules-driven product that can adapt literally every aspect of your app:  customize the user interface, enable or disable different features, customized messaging and notifications, and much more, all variable based upon the user context.  This can be used to present contextually relevant information, drive adoption, provide more/less data depending on your physical context, and so much more.

It won’t be tied to a specific UI framework, won’t be tied to a specific content management system, isn’t attempting to re-create Google Now or Apple Proactive Assistance.  Rather, a set of tools and a rules engine that enable you to customize and tailor the app experience to the individual user.

Head over to http://adaptiveexperience.mybluemix.net/ to learn more and get involved!

Data Management for Apps that Work as Well Offline as They Do Online

Earlier this week I had the privilege of speaking at ApacheCon in Austin, TX on the topic of data management for apps that work as well offline as they do online.  This is an important topic for mobile apps, since, as we all painfully know already, there is never a case when you are always online on your mobile devices.  There always ends up being a time when you need your device/app, but you can’t get online to get the information you need.  Well, this doesn’t always have to be the case. There are strategies you can employ to build apps that work just as well offline as they do online, and the strategy I’d like to highlight today is based upon data management using the IBM Cloudant NoSQL database as a service, which is based upon Apache CouchDB.

Here’s a link to the presentation slides (built using reveal.js) – just use the space bar to advance the presentation slides:

The “couch” in CouchDB is actually an acronym for Cluster of Unreliable Commodity Hardware. At the core of this cluster is the concept of replication, which in the most basic of terms means that  data is shared between multiple sources.  Replication is used to share information between nodes of the cluster, which provides for cluster reliability and fault tolerance.

Replication between Nodes
Replication between Nodes (source)

If you’d like to learn more about replication in Cloudant and CouchDB, you can read more using the links below:

Cloudant is a clustered NoSQL database services that provides an extremely powerful and searchable data store.  It is designed to power the web and mobile apps, and all information is exposed via REST services. Since the IBM Cloudant service is based on CouchDB (and not so coincidentally, IBM is a major contributor to the CouchDB project), replication is also core the the Cloudant service.

With replication, you only have to write your data/changes to a single node in the cluster, and replication takes care of propagating these changes across the cluster.

If you are building apps for the web or mobile, there are options to extend the data replication locally either on the device or in the browser.   This means that you can have a local data store that automatically pushes and/or pulls data from the remote store using replication, and it can be done either via native languages, or using JavaScript.

If you want to have local replication in either a web or hybrid (Cordova/PhoneGap) app, you can use PouchDB.  PouchDB is a local JavaScript database modeled after CouchDB and implements that CouchDB replication API.  So, you can store your data in the browser’s local storage, and those changes will automatically be replicated to the remote Cloudant store.  This works in the browser, in a hybrid (web view) app, or even inside of a Node.js instance. Granted, if you’re in-browser you’ll need to leverage the HTML5 cache to have your app cached locally.

If you are building a native app, don’t worry, you can take advantage of the Cloudant Sync API to leverage the local data store with replication.  This is available for iOS and Android, and implements the CouchDB replication API.

The sample app that I showed in the presentation is a native iOS application based on the GeoPix MobileFirst sample app that I detailed in a previous post.  The difference is that in this case I showed it using the Cloudant Sync API, instead of the MobileFirst data wrapper classes, even though it was pointing at the exact same Cloudant database instance.  You can see a video of the app in action below.

All that you have to do is create a local data store instance, and then use replication to synchronize data between the local store and a remote store.

Replication be either one-way (push or pull), or two-way.  So, any changes between the local and remote stores are replicated across the cluster.  Essentially, the local data store just becomes a node in the cluster.  This provides complete access to the local data, even if there is no network available.  Just save your data to the local store, and replication takes care of the rest.

In the native Objective-C code, you just need to setup the CDTDatastore manager, and initialize your datastore instance.

self.manager = [[CDTDatastoreManager alloc] initWithDirectory:path error:nil];
self.datastore = [self.manager datastoreNamed:@"geopix" error:nil];

Once your datastore is created, you can read/write/modify any data in the local store.  In this case I am creating a generic data object (basically  like a JSON object), and creating a document containing this data.  A document is a record within the data store.

You can add attachments to the document or modify the document as your app needs.  In the code below, I add a JPG atttachment to the document.

//create a document revision
CDTMutableDocumentRevision *rev = [CDTMutableDocumentRevision revision];
rev.body = @{
			 @"sort": [NSNumber numberWithDouble:[now timeIntervalSince1970]],
			 @"clientDate": dateString,
			 @"latitude": [NSNumber numberWithFloat:location.coordinate.latitude],
			 @"longitude": [NSNumber numberWithFloat:location.coordinate.longitude],
			 @"altitude": [NSNumber numberWithFloat:location.altitude],
			 @"course": [NSNumber numberWithFloat:location.course],
			 @"type": @"com.geopix.entry"
			 };

//add the jpg attachment
NSData *imageData = UIImageJPEGRepresentation(image, 0.1);
[imageData writeToFile:imagePath atomically:YES];
 
CDTUnsavedFileAttachment *att1 = [[CDTUnsavedFileAttachment alloc]
								  initWithPath:imagePath
								  name:imageName
								  type:@"image/jpeg"];

rev.attachments = @{ imageName: att1 };

//create a new document from the revision
NSError *error = nil;
CDTDocumentRevision *doc = [self.datastore createDocumentFromRevision:rev error:&error];

if (doc == nil) {
	[logger logErrorWithMessages:@"Error creating document: %@", error.localizedDescription];
}

[logger logDebugWithMessages:@"Document created ID: %@", doc.docId];

Replication is a fire-and-forget process.  You simply need to initialize the replication process, and any changes to the local data store will be replicated to the remote store automatically when the device is online.

//initialize the replicator factory with the local data store manager
CDTReplicatorFactory *replicatorFactory = 
	[[CDTReplicatorFactory alloc] initWithDatastoreManager:self.manager];

NSURL *remoteDatabaseURL = [NSURL URLWithString:REMOTE_DATABASE_URL];

//setup push replication for local->remote changes
NSError *error = nil;
CDTPushReplication *pushReplication = 
	[CDTPushReplication replicationWithSource:self.datastore target:remoteDatabaseURL];

//create the replicator instance
self.replicator = [replicatorFactory oneWay:pushReplication error:&error];
if (!self.replicator) {
	[logger logErrorWithMessages:@"An error occurred: %@", error.localizedDescription];
}

//assign the replicator delegate
self.replicator.delegate = self;

//auto start replication
error = nil;
if (![self.replicator startWithError:&error]) {
	[logger logErrorWithMessages:@"An error occurred: %@", error.localizedDescription];
}

By assigning a replicator delegate class (as shown above), your app can monitor and respond to changes in replication state.  For example, you can update status if replication is in progress, complete, or if an error condition was encountered.

- (void)replicatorDidChangeState:(CDTReplicator *)replicator {
    [logger logDebugWithMessages:@"Replicator changed State: %@", [CDTReplicator stringForReplicatorState:replicator.state]];
}

- (void)replicatorDidChangeProgress:(CDTReplicator *)replicator {
    [logger logDebugWithMessages:@"Replicator progress: %d/%d", replicator.changesProcessed, replicator.changesTotal];
    
    NSDictionary *userInfo = @{ @"status":[NSString stringWithFormat:@"%d/%d", replicator.changesProcessed, replicator.changesTotal] };
    
    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"ReplicationStatus"
     object:self
     userInfo:userInfo];
}

- (void)replicatorDidError:(CDTReplicator *)replicator info:(NSError *)info {
    [logger logErrorWithMessages:@"An error occurred: %@", info.localizedDescription];
    self.replicator = nil;
    
    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"ReplicationError"
     object:self];
}

- (void)replicatorDidComplete:(CDTReplicator *)replicator {
    [logger logDebugWithMessages:@"Replication completed"];
    self.replicator = nil;
    
    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"ReplicationComplete"
     object:self];
}

If you want to access data from the local store, it is always available within the app, regardless of whether or not the device has an active internet connection.  For example, this method will return all documents within the local data store.

-(NSArray*) getLocalData {
    
    NSArray *docs = [self.datastore getAllDocuments];
    return docs;
}

Be sure to review the documentation and/or Cloudant Synch API source code for complete details.

Helpful Links

Video: The Next Generation of Native Apps Built with IBM MobileFirst

Last month I had the opportunity to speak at the DevNexus developer conference in Atlanta on building native iOS apps IBM MobileFirst. DevNexus is a great event, and it is always a privilege to attend – I highly recommend it for next year.   If you weren’t able to make it, no worries!  Most of the sessions were recorded and are available for viewing online via dzone.

The recording of my session is embedded below.  It covers everything you need to know to get started building apps with the MobielFirst platform.

This session focuses mainly on native iOS, but the exact sample concepts apply to MobileFirst apps built for other platforms or hybrid apps.  It covers both the MobileFirst for Bluemix (Cloud) and on-premise MobileFirst Platform Foundation Server solutions.

Here’s the “official” session description:

Once your app goes live in the app store you will have just entered into an iterative cycle of updates, improvements, and releases. Each successively building on features (and defects) from previous versions. IBM MobileFirst Foundation gives you the tools you need to manage every aspect of this cycle, so you can deliver the best possible product to your end user. In this session, we’ll cover the process of integrating a native iOS application with IBM MobileFirst Foundation to leverage all of the capabilities the platform has to offer.

Video originally shared by @dzone.

Updated: Parallax Effects in Hybrid/Web Apps

A while back I wrote about adding parallax effects to your HTML/JS experiences to make them feel a bit richer and closer to a native experience.  I’ve just added this subtle (key word *subtle*) effect to a new project and made a few changes I wanted to share here.

If you are wondering what I am talking about with “parallax effects” – Parallax movement is where objects in the background move at a different rate than objects in the foreground, thus causing the perception of depth.  Read more about it if you’re interested.

First, here’s a quick video of this latest app in action.  It’s a hybrid MobileFirst app, but this technique could be used in any Cordova/PhoneGap/MobileFirst/mobile web app experience.  The key is to keep it subtle and not too much “in your face”, and yes, it is very subtle in this video.  You have to watch closely.

The techniques that I wrote about in the previous post still apply – I’ve just added a bit more to cover more use cases.

First let’s look at the CSS.

body {
    background-image: url('../images/cloud_advisor_bkgd.png');
    background-attachment: fixed;
    background-position: center;
    background-size: auto 120%;
}

This sets the background image and default position.  The distinct change here is that I set the background size to “auto” width and 120% height.  In this case, you can have a huge image that shrinks down to just slightly larger than the window size, or a small image that scales up to a larger window size.  This way you don’t end up with seams in a repeated background or a background that is too big to highlight the parallax effect effectively.

Next let’s take a quick look at the JS involved.

var position = "center";
var lastPosition = "center";
var contentCSS = "";
var body = $("body");
var content = $(".content");
window.suspendAnimation = false;

var xMovement = 15;
var yMovement = 30;
var halfX = xMovement/2;
var halfY = yMovement/2;

window.ondeviceorientation = function(event) {
 var gamma = event.gamma/90;
 var beta = event.beta/180;

 var temp = 0;

 //fix for holding the device upside down
 if ( gamma >= 1 ) {
  gamma = 2- gamma;
 } else if ( gamma <= -1) {
  gamma = -2 - gamma;
 }

 // shift values/motion based upon device orientation
 switch (window.orientation) {
  case 90:
   temp = gamma;
   gamma = beta;
   beta = temp;
   break;
  case -90:
   temp = -gamma;
   gamma = beta;
   beta = temp;
   break;

 }

 // update positions to be used for CSS
 var yPosition = -yMovement - (beta * yMovement);
 var xPosition = -xMovement - (gamma * xMovement);
 var contentX = (-xMovement - xPosition)/2;
 var contentY = (-yMovement - yPosition)/2;

 // generate css styles
 position = xPosition.toFixed(1) + "px " + yPosition.toFixed(1) + "px";
 contentCSS = "translate3d( " + (contentX.toFixed(1)) + "px, " + (contentY.toFixed(1)) + "px, " + " 0px)";
}

function updateBackground() {

 if (!window.suspendAnimation) {
  if ( position.valueOf() != lastPosition.valueOf() ) {

   body.css( "background-position", position);
   content.css( "-webkit-transform", contentCSS);
   lastPosition = position;
  }
 } else {
  lastPosition = "translate3d(0px, 0px, 0px)";;
 }

 window.requestAnimationFrame(updateBackground);
}

window.requestAnimationFrame(updateBackground);

The html where this would be used would be something like this:

<body>
  <div class="content">put your foreground stuff here.</div>
</body>

There are some subtle but important changes here:

  1. In the requestAnimationFrame loop, it only applies changes *if* there are changes to apply.  This prevents needless calls to apply CSS even if the CSS styles hadn’t changed.  In this, I also truncate the numeric CSS string so that it isn’t reapplying CSS if the position should shift by 0.01 pixels. Side note: If you aren’t using requestAnimationFrame for HTML animations, you should learn about it.
  2. If you used my old code and were holding the device upside down, it wouldn’t work.  Not even a little bit.  This has that fixed (see comments inline above).
  3. This moves the background in CSS, which doesn’t cause browser reflow operations, and moves the foreground content (inside of a div) using translate3d, which also doesn’t cause browser reflow operations.  This helps keep animations smooth and the UX performing optimally.
  4. I also added a global variable to turn parallax on and off very quickly, if you need it.

The result is a faster experience that is more efficient and less of a strain on CPU and battery.  Feel free to test this technique out on your own.

If you use the code above, you can modify the xMovement and yMovement variables to exaggerate the parallax effect.

Getting Started with IBM Bluemix Mobile Services (MBaaS)

I recently wrote an overview of IBM Bluemix’s Mobile Back-end as a Service offerings. I wanted to elaborate on the offerings, plus provide in-depth technical and implementation details, so I decided to produce this 5 part video series on Getting Started with IBM Bluemix Mobile Services.

This post specifically covers native iOS, though there are also Android and hybrid options available. This should have everything you need to get started. It covers all aspects from creating the app, to updating the back end, to leveraging Cloudant storage, push notifications, and monitoring & logging.

So, without further ado, let’s get started…

Part 1: Getting Started with Bluemix Mobile Services

In this first video I show how to create a new mobile app on Bluemix, connect to the cloud app instance, and implement remote logging from the client application. This process is covered in more detail in the Getting Started docs, but below are the basics from my experience.

You’ll first need to sign into your Bluemix account. If you don’t already have one, you can create a trial account for free. Once you’re signed in, you just need to create a new mobile app instance.

The process is very simple, and there is a “wizard” to guide you. The first thing that you need to do is create a new app by clicking the big “Create an App” button on your bluemix dashboard.

Create a new app from IBM Bluemix Dashboard
Create a new app from IBM Bluemix Dashboard

Next, select which kind of app you’re going to create. For MBaaS, you’ll want to select the “Mobile” option.

Select the type of app
Select the type of app

Next you’ll need to select your platform target. You can choose either “iOS, Android, Hybrid”, or the “iOS 8 beta” target. In this case I chose the iOS 8 beta, but the process is similar for both targets. Hybrid apps are built leveraging the Apache Cordova container.

Select your platform target
Select your platform target

Next, just specify an app name and click “Finish”.

Give your app a name
Give your app a name

Once your app is created, you will be presented with instructions how to connect the app in Xcode. I’ll get to that in a moment…

Now that your app has been created, you’ll be able to see it on your Bluemix dashboard. This app will consist of several components: a Node.js back-end instance, a Cloudant NoSQL database instance, an Advanced Mobile Access instance, and a Push instance. The Advanced Mobile Access component provides you with app analytics, user auth management, remote logging, and more. The Push component gives you the ability to manage and send push notifications (either manually, or with a rest-based API).

You app has been created
You app has been created – here are the components and the activity

Once your app has been created, you will need to setup the mobile app to connect to Bluemix to consume the services. Again, this is a very straightforward process.

The next step is to register your client application. Once your app is created, you will be presented with a screen to do this. If you don’t complete it right away, you can always come back later and register an application. You’ll need to specify the Bundle ID and version of your app, then you can setup any authentication (if you choose).

Register your app's bundle ID and version
Register your app’s bundle ID and version

Once your app has been registered, you need to configure Xcode. You’ll first need to create a new project in Xcode. There are two options for configuring your Xcode project: 1) automated installation using CocoaPods, or 2) manual installation. I used the CocoaPods installation simply because it is easier and manages dependencies for you.

If you aren’t familiar with CocoaPods, it is much like NPM… CocoaPods is a dependency manager for Cocoa projects. It helps you configure the Bluemix libraries and manages dependencies for you.

If you’ve got Xcode up and running, then close it and install CocoaPods, if you don’t already have it. Next open up a terminal/command prompt, go to the directory that contains your Xcode project and initialize CocoaPods using the “setup” command:

pod setup

This will create a new file called “podfile”. Open this file in any text editor and paste the following (note: you can remove any lines that you don’t want to actually use):

source 'https://github.com/CocoaPods/Specs.git'
# Copy the following list as is and
# remove the dependencies you do not need
pod 'IMFCore'
pod 'IMFGoogleAuthentication'
pod 'IMFFacebookAuthentication'
pod 'IMFURLProtocol'
pod 'IMFPush'
pod 'CloudantToolkit'

Save the changes to the “podfile” file, and close the text editor. Then go back to your command promprt/terminal  and run the installation process:

pod install

Your project will be configured, and all dependencies will be downloaded automatically. Once this is complete, open up the newly created .xcworkspace file (Xcode Workspace).

You have to initialize the Bluemix inside of your application to connect to the cloud service to be able to take advantage of any Bluemix features (logging, data access, auth, etc…). The best place to put this is inside of your AppDelegate.m class application didFinishLaunchingWithOptions method because it is the first code that will be run within your application:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.

    // initialize SDK with IBM Bluemix application ID and route
    IMFClient *imfClient = [IMFClient sharedInstance];
    [imfClient
        initializeWithBackendRoute:@"your route"
        backendGUID:@"your guide"];

    return YES;
}

One of the first features I wanted to take advantage of was remote collection of client-side logs. You can do this using the IMFLogger class, in much the same fashion as you do with OCLogger in MobileFirst Foundation server. Once great feature that requires almost no additional configuration is the captureUncaughtExceptions method, which automatically configures the Advanced Mobile Access component to collect information for all app crashes.

// capture and record uncaught exceptions (crashes)
[IMFLogger captureUncaughtExceptions]; 

// change the verbosity filter to "debug and above"
[IMFLogger setLogLevel:IMFLogLevelDebug]; 

// create a logger instance
IMFLogger *logger = [IMFLogger loggerForName:@"AppDelegate"];

// log a message
[logger logDebugWithMessages:@"This is a log message from app launch."];

//send logged message to the server
[IMFLogger send];

Next, launch your app in the iOS simulator, or on a device, and you’ll see everything come together. Log into your Bluemix dashboard, and you’ll be able to monitor app analytics and remote logs.

Note: If you experience any issues connecting to the Bluemix mobile app from within the iOS simulator, just clear the iOS Simulator by going to the menu command “iOS Simulator -> Reset Content and Settings…”, and everything should connect properly the next time you launch the app.

Part 2: Configuring the Node.js Backend

In the next video, I demonstrate how to grab the code for the backend Node.js application, create a git repository on IBM JazzHub, then pull the code for local development.

There are two ways to push new backend Node.js code: 1) Using the Cloud Foundry command line API, or 2) by updating a git repository and leveraging automatic deployment from the git repo commits.

When the app is created, you’ll see an “add git” link under the app name. Using this link, you can create a git repository for the backend code.

Add a git repository
Add a git repository

Once your git repo has been created, you can check out the code using any Git client (I used the CLI). You’ll need to use the “npm install” command to pull down all the app dependencies. The biggest thing you need to know is that it uses express.js for the web application framework.  You can make any changes that you want, and they will be automatically deployed to your Bluemix server instance upon commit. Yes, this workflow is also configurable b/c this process may not work for everyone.

One other thing that you will need to watch out for if you are doing local development: You will want to wrap the following code on line 6 in a try/catch block, otherwise you will hit errors in the local environment which will prevent your app from launching locally:

try {
    passport.use(new ImfBackendStrategy());
} catch ( e ) {
    console.log(e);
}

Protected content behind the /protected url endpoint may not be accessible locally with this workaround, but you’ll be able to work on other pieces of your back end.

You can read more about the backend node instance for Bluemix mobile apps in the developer documentation.

Part 3: Consuming Data from Cloudant

Another part of Bluemix mobile applications is the Cloudant NoSQL database. The Cloudant NoSQL database is a powerful solution that gives you remote storage, querrying, and client-side data storage mechanisms with automatic online/offline synchronization, all with monitoring/analytics capabilities.

By default, objects within the Cloudant data store are treated as generic objects (over-simplification: think of it is an extremely powerful JSON store in the cloud). However you can also serialize your objects to strong data types within the client code configuration.

In your AppDelegate class application didFinishLaunchingWithOptions method, you’ll also want to initialize the IMFDataManager class, which is the class used for interacting with all Cloudant data operations.

IMFDataManager *manager =
    [IMFDataManager sharedInstance];

In my sample, I setup the database manually with open permissions, but you’ll probably want something more secure. Once your database is created, you can create indexes, search for data, create data, etc…

In the following code, I create a search index and query for data from the remote Cloudant database. You really only need to create the index if it doesn’t already exist. You can do this either through the mobile app code, or manually through the Cloudant database’s web interface. I did this inline in the following code, just for the sake of simplicity:

//access the remote data store
[[IMFDataManager sharedInstance] remoteStore:@"insurancedb" completionHandler:^(CDTStore *store, NSError *error) {
    // Remote store will be passed into the control handler if no errors occurred.

    // create a search index
    // this is an asynch operation
    [store createIndexWithName:@"customerNameIndex" fields:@[@"customer"] completionHandler:^(NSError *error) {
        // an error is set if index creation failed.

        // Next, we search...
        // Create a query with an NSPredicate
        NSPredicate *queryPredicate = [NSPredicate predicateWithFormat: @"(customer > '')"];
        CDTCloudantQuery *query = [[CDTCloudantQuery alloc] initDataType:@"Claim" withPredicate:queryPredicate];

        [store performQuery:query completionHandler:^(NSArray *results, NSError *error) {
            // results is an array of CDTMutableDocumentRevision objects that are returned by the query

            // convert to a NSArray of NSDictionary objects
            // you could also serialize this to an array of strongly typed objects
            NSMutableArray *array = [[NSMutableArray alloc] init];

            for (CDTMutableDocumentRevision *revision in results) {
                NSDictionary *body = [revision body];
                [array addObject:body];
            }

            // do something with the data (this is specific to my app)
            claimsData = array;

            // reload my data table in the main thread
            dispatch_async(dispatch_get_main_queue(), ^{
                [self reloadData];
            });

        }];
    }];
}];

Be sure to also read up on more of the Cloudant capabilities:

Part 4: Push Notifications

The IBM Bluemix mobile services app also contains a component for managing push notifications within your mobile applications. With this service, you can send push notifications to a specific device, a group of devices using tags, or all devices, and you can send push notifications either manually via the web interface, or as part of an automated workflow using the REST API.

You will first need to configure your app for push notifications. Apple systems using Apple’s Push Notification Service, and Android systems use Google Cloud Messaging. You must configure these hooks per the service providers.

For iOS apps, here are the basic steps for setting up the Push service. It also helps to be familiar with Local and Remote notifications in iOS.

  1. Create an App ID and enable Push Notifications
  2. Create a server certificate for sending push notifications
  3. Upload the server certificate to the Bluemix Push instance
  4. Setup the Xcode project to receive push notifications

In Xcode, open your AppDelegate class again. First you’ll need to register for remote notifications in application didFinishLaunchingWithOptions:

//register for push notifications (iOS 8-specific)
[[UIApplication sharedApplication] registerUserNotificationSettings:
    [UIUserNotificationSettings settingsForTypes:
        (UIUserNotificationTypeSound |
          UIUserNotificationTypeAlert |
          UIUserNotificationTypeBadge)
        categories:nil]];
[[UIApplication sharedApplication]
    registerForRemoteNotifications];

Next, setup the didRegisterForRemoteNotificationsWithDeviceToken callback to register this device with the Bluemix Push service:

-(void) application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{

    // get Push instance
    IMFPushClient* push = [IMFPushClient sharedInstance];

    // set current working environment
    push.environment = @"sandbox";

    [push registerDeviceToken:deviceToken completionHandler:^(IMFResponse *response, NSError *error) {

        IMFLogger *logger = [IMFLogger loggerForName:@"AppDelegate"];

        if (error){
            [logger logErrorWithMessages:@"error registering for push notifications: %@", error.description];
        } else {
            [logger logDebugWithMessages:@"registered for push notifications."];
        }
    }];
}

Next do something with the data whenever you receive a push notification inside of the didReceiveRemoteNotification method:

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    //userInfo dictionary will contain data sent from server.

    NSDictionary *notification = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
    NSString *body = [notification objectForKey:@"body"];

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Notification Received"
                                                    message:body delegate:self cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil, nil];
    [alert show];
}

Part 5: Monitoring and Logging

Did I mention that every action that you perform through Bluemix Mobile Services can be monitored? Analytics are available for the Advanced Mobile Access component, the Cloudant NoSQL data store, and the Push Notifications service. In addition, you also have remote collection of client logs and crash reports. This provides  unparalleled insight into the health of your applications.

Need more info? You can find what you’re looking for here:

…. and of course, don’t forget the full 5-part video series available at https://www.youtube.com/playlist?list=PL0U4cUwfUs26kSKY0X-qdDNO5gKj6Lr6q

Ready to get started? Just head over to bluemix.net and create your first app!