Trigger.io and Apigee enable fast mobile app development for the enterprise

The shift to mobile makes it necessary for enterprises to change the way they engage their customers – we see the opportunity all the time with new consumer services such as Uber and Exec disrupting older models. To keep up, enterprises need to find ways to reach their customers through new types of applications.

Trigger.io allows enterprises to reuse their existing web skills and investments to create native mobile apps while Apigee enables “business-as-service” – allowing an enterprise’s business value to be consumed by their customers in new ways through APIs.

You can create a native mobile app for iOS, Android or Windows Phone using an enterprise-ready back-end in just a few minutes using Trigger.io with Apigee.

We recently created such an app. This blog post summarizes the steps we took. We’ll cover:

Getting started with Trigger.io and Apigee’s App Services data store

Creating a simple mobile app using Apigee’s HTML5 example code with Trigger.io and testing it in the iOS emulator

Setting up Trigger.io with Apigee

We’ll create an example app called Messagee – a simple HTML5 Twitter clone. We’ll get it running as a native mobile app that can be submitted to the App Store or Google Play. To do this you need to:

Click ‘Create’ in the Trigger.io Toolkit, entering ‘Messagee’ as the app name and selecting the default location.

You’ll now be able to see the app in the homepage of the Toolkit with the path to the code location.

To get the example code running with Trigger.io you need to copy the code into your app’s ‘src’ subdirectory while keeping the ‘src/config.json’ and ‘src/identity.json’ files that were automatically created.

To do this, open up a terminal navigate to the app directory and run the following commands:

1

2

3

4

5

6

7

cd src

mv identity.json..

mv config.json..

rm-rf *

git clonehttps://github.com/apigee/usergrid-sample-html5-messagee .

mv../identity.json.

mv../config.json.

Make one code change to the index.html file that you cloned from the GitHub repos to customize it for your account. That file should now be in ‘src/index.html’ and you need to change one line to reference your Usergrid app. For example:

After just a few minutes we already can see the app running in the iOS emulator:

Create an account in the app, compose a new message for your stream and try it out!

Apigee makes remote data storage simple

Ok now we have the app up and running in the emulator let’s take a look at the code.

The app using jQuery Mobile to handle various UI elements and navigation and Apigee’s JavaScript SDK to make accessing a remote data store simple.

You can see the JavaScript SDK in the usergrid.appSDK.js file. This makes it super simple to store and retrieve data from the Apigee backend. For example, in app.js, setting up your data objects takes just a few lines and no server-side configuration using Apigee’s JavaScript SDK:

1

2

3

4

5

6

7

8

9

10

11

12

//a new user object

varappUser=newUsergrid.Entity('user');

//a new Collection object that will be used to hold the full feed list

varfullActivityFeed=newUsergrid.Collection("activities");

//make sure messages are pulled back in order

fullActivityFeed.setQueryParams({"ql":"order by created desc"});

//default to full feed view

varfullFeedView=true;

//a new Collection object that will be used to hold the user's feed

varuserFeed=newUsergrid.Collection('users/me/feed');

//make sure messages are pulled back in order

userFeed.setQueryParams({"ql":"order by created desc"});

Then later in the code we can see it reading from the user’s feed and using the data to render the HTML:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

//get the users feed

userFeed.get(

function(){

drawMessages(userFeed);

if(userFeed.hasPreviousPage()){

$("#previous-btn-container").show();

}else{

$("#previous-btn-container").hide();

}

if(userFeed.hasNextPage()){

$("#next-btn-container").show();

}else{

$("#next-btn-container").hide();

}

},

function(){

$("#messages-list").html("There was an error getting the messages!");

}

);

functiondrawMessages(feed){

varhtml="";

varusersToBind=[];

feed.resetEntityPointer();

while(feed.hasNextEntity()){

varmessage=feed.getNextEntity(),

created=message.get('created'),

content=message.get('content'),

...

Let’s reiterate: you have created a remote data store using Apigee without ever needing to provision a server of your own, and you’ve created a native iOS app that’s now running in the emulator using HTML / CSS / JavaScript and not a hint of Objective-C in sight!

Pretty cool…

Adding Native Mobile Features

It gets even better – now that you have the basic HTML5 example app running with Trigger.io you can add native mobile features to it.

For example, you may want to replace the jQuery mobile titlebar with a genuine native topbar element. Here’s how to do this with Trigger.io’s Forge platform:

Firstly, let’s enable the native modules we need in src/config.json. We’ll add the topbar, contact and sms modules. You can do that easily by checking the right boxes in your app’s App Config tab in the Trigger.io Toolkit:

Now let’s remove the existing jQuery Mobile header – that isn’t really native, just HTML and CSS faked to look close to native. So let’s remove all div elements with data-role=”header” in index.html, like this one:

Then we can add controls for the native header in our JavaScript at the bottom of app.js.

Notice how we add buttons to the native topbar using the Trigger.io Forge JavaScript API and can set the styling and callback functions:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

functionaddTopbarButtons(){

forge.topbar.addButton({

text:"Logout",

position:"left"

},function(button){

logout();

});

forge.topbar.addButton({

text:"Settings",

position:"right"

},function(){

window.location="#page-update-account";

forge.topbar.removeButtons();

});

}

forge.topbar.setTitle('Messagee');

forge.topbar.setTint([57,107,158,1]);

Finally we need to add and remove the buttons according to navigation within the app. Search app.js for places where we set window.location and use the Trigger.io Forge API to remove the buttons where we navigate away from the main feed page and add them back when we navigate to it e.g.

1

2

3

4

5

window.location="#page-login";

forge.topbar.removeButtons();

window.location="#page-messages-list";

addTopbarButtons();

Great! You’re ready to test the app again – if you run the app in the iOS emulator by clicking the iOS link in the Trigger.io Toolkit and logging in, you’ll see the native topbar with buttons like in the screenshot at the top of this post.

Adding contact selection and SMS features

Now let’s add an option so that when a user posts a new message to their feed they can also send the same message by SMS to one of their contacts.

That’s super simple with Trigger.io Forge – we’ve already enabled the contact and SMS modules in the App config tab in the Toolkit. So all we need to do is:

Add a new ‘Post & SMS’ button to the create new message view by modifying index.html:

That’s it

The final code for the Messagee app with the native features described here is available on Github.

What’s next?

If you like what you’ve read and would like to keep going, here are a few things to try:

How about replacing the jQuery Mobile buttons to navigate between the feeds and settings view with a native tabbar component.

Try testing the app on an actual iOS device rather than just the emulator to see the phone contacts and SMS access live. That’ll require you to setup an Apple developer account and configure your provisioning profile and certificate in the Local config tab in the Trigger.io Toolkit