Message:

Subscribe rss
Blog categories

In this blog post we review the process of setting up and developing an iOS application capable to receive Apple Push Notifications. We also review the functionality of publishing a push notification through Backendless.

Creating App ID

  1. First we are going to create an App ID for the application which will receive Push Notifications. Login to Apple Developer Member Center. Click on “App IDs” in the “Identifiers” section. Use the plus sign “+” button to create a new ID:
  2. When prompted enter App ID Prefix. Make sure it is descriptive enough so you recognize it later when you return to the Member Center.
  3. Select Explicit App ID in the “App ID Suffix” section and enter the same bundle ID which you will be using in the application:
  4. In App Services select the services which the application will use and click “continue”:
  5. Make sure that Push Notifications are enabled and click “submit”. This will conclude the App ID creation for the app:

Creating Certificate Request

Push Notifications require a certificate which will be used on a device by the means of a provisioning profile. Also the same certificate (transformed to the Personal Information Exchange – .p12 format) will be used by Backendless to publish Push Notifications. If this makes little sense, do not worry, you will need to perform these steps only ones and then can move on to code and using the APIs.

  1. In order to create a certificate a Certificate Signing Request (CSR) must be issued. To create a CSR, open Keychain Access and select Keychain Access >> Certificate Assistant >> Request a Certificate from the main menu:
  2. Enter your email address and Common Name (leave the CA Email Address field empty), select “Saved to disk” and click “Continue”:
  3. Select a directory where to save the file and click Save.

Generating an SSL Certificate for Push Notifications

The CSR file created in the section above will be used to create an SSL Certificate. That certificate will then be used by Backendless to publish push notifications.

  1. Return to Apple Developer Member Center and select “All” under “Certificates”. Click the plus button “+” to add a new certificate:
  2. Select certificate type – there are two options Development and Production. For now select “Apple Push Notification service SSL (Sandbox)”:
  3. Select the App ID created earlier in these instructions:
  4. Next you will see the instructions for generating a CSR which you have already created by now. Click Continue to proceed to the next step.
  5. Select the CSR file created and saved to the disk earlier and click Generate:
  6. The certificate is ready now, click “Download” to download it:
  7. Add the certificate file to Keychain Access.
  8. Open Keychain Access and locate the certificate in the “My Certificates” section:
  9. Right click on the certificate and select the Export option:
  10. Save the certificate in the p12 format:
  11. Enter a password for the certificate. Make sure to make a record of the password – you will need to use it later in the instructions when you submit the certificate to Backendless:
  12. Enter your Mac OS X account password to confirm the action. At this point you have a certificate for Push Notifications.

Configuring Backendless App with the Certificate

Since Backendless provides the actual server-side integration for delivering Push Notifications for your application, it needs to have access to the certificate you created above. The steps below provide the instructions for uploading the certificate into Backendless:

  1. Login to Backendless Console at: https://backendless.com/develop and create/select an application which you will use on the server-side:

  2. Click Manage > App Settings. Locate the Mobile Settings section and upload the .p12 certificate created earlier. Make sure to enter the same password you used when created the certificate:

  3. Now your Backendless server is ready to publish Push Notifications.

Creating Provisioning Profile

  1. Login to Apple Developer Member Center and select “All” under Provisioning Profiles. Click the plus button “+” to create a new profile:
  2. Select the “iOS App Development” profile type:
  3. Click Continue. On the next screen select the App ID which was created earlier:
  4.  Click Continue. Select the users/certificates which will be included into the profile.
  5. Click Continue. Select the devices to include into the profile.
  6. Click Continue. Enter a name to assign to the profile and click Generate:
  7. Download the profile:
  8. Start XCode and open Organizer. Select the Provisioning Profiles section and add the profile you generated/downloaded:

Creating App in XCode

Finally all the setup is done and we can proceed to the fun part – creating an app in XCode and writing some code.

  1. Open XCode and create new “Single View Application”.
  2. Enter “pushNotificationSample” as the Product Name. Also provide your organization name and company identifier. Since the bundle ID we used when creating App ID earlier was “com.backendless.pushNotificationSample”, you should use “com.backendless” as the “Company Identifier”:
  3. Once the application is created, open Targets > Build Settings > Code Signing > Code Signing Identity and select the provisioning profile created earlier:



  4. At this point you should add Backendless SDK to your project. This includes adding Backendless library and its dependencies. Additionally, you will need to copy/paste Backendless Application ID and Secret Key into the code. For detailed instructions on how to do that, please follow the Backendless Quick Start Guide for iOS.
  5. Open AppDeletage.m. The following code registers the device with Backendless and Apple Push Notification Service:

    If the registration goes through, the following method is automatically called with the device token passed as the argument:

    Otherwise, if the registration fails, the following method is called with the argument of the underlying error:

    In case of the successful registration, the device is ready to accept published Push Notifications. When a notification is delivered to a device, the following method is invoked when the app is running.
  6. In order to send a Push Notification from a device, use the following code:

Publishing Push Notifications from Backendless Console

  1. Open Backendless Console at https://backendless.com/develop and select the Messaging section.
  2. Enter the text of the notification message in the “Message text” area, also make sure to specify the headers:
    1. “ios-badge”:”X”, where X is the number for the badge update
    2. “ios-alert”:”alert message text”
    3. “ios-sound”:”URL of the sound file”For a list of all supported headers, see the Publish Push Notification section in the documentation.
  3. Click the “iOS Devices” checkbox.
  4. Click Publish. The Push Notification will be delivered to all registered iOS devices:
  5. To see a list of the registered devices use the Devices tab. You can also send a push notification to specific devices. In order to do that, select the devices using the checkboxes and then click the “Selected devices” option under “Push Notification” section:

Blocks are a powerful C-language feature that is part of Cocoa application development. They are similar to “closures” and “lambdas” you may find in scripting and programming languages such as Ruby, Python, and Lisp. For a more in-depth review of blocks, see “a short practical guide to blocks”. A Backendless user has recently asked us about the ability to handle asynchronous APIs via block-based callbacks. Since this is a very reasonable request, we added support for blocks and it is available in the latest version of the Backendless SDK for iOS. Below is an example of using the new feature with the user registration and login APIs (btw, the feature is available for ALL Backendless APIs):

By the way, here is an example of code that does the same thing, but synchronously:

The example below demonstrates the usage of block callbacks with the Data Service API in order to:

  • Persist a complex type (an instance of class Weather)
  • Find an object by ID
  • Finding first and last instances
  • Deleting an object by its objectId

If you prefer to use the synchronous (blocking) API, the follow code does the same thing as the example above (but synchronously):

Enjoy!

Posted in Examples, iOS

Differentiating user behavior in an application by roles is a very common practice. Indeed, as long as you have different workflows in the application, it is likely each workflow would be associated with a specific user role. Take for an instance a mobile application to reserve a taxi. One of the user types (roles) is a client making a reservation, another one is a taxi driver for whom the reservation is dispatched to. Users in either role will have a separate login form, they will access the same data (reservation), but will see different aspects of it. Another example may be an application coordinating appointments with a gym’s private trainer. One user role in such an app is going to be the trainees coming to the gym for the workouts and another one are the trainers with whom people make appointments. In these apps users in different roles are likely to have different entry points into the application (different login forms) as well as different access level to the applications’ data.

Backendless simplifies roles-based access to data through a flexible permission system. Each role may have its own set of permissions either granting or denying access to various Backendless resources like data tables, messaging channels or media streams. The API provides a way to associate a user with a particular role. Once a user is linked to a role, any restrictions that the role has will automatically apply to the API operations made in the user’s session.

The example reviewed in this post demonstrates the roles-based data access concept. The example is an Android application. It defines two Backendless roles – ReadOnlyRole and ReadWriteRole. The first role has the read-only access to data, the second one has unlimited permissions. There are also two login forms – when a user logs in using the first form, his account is associated with the ReadOnlyRole. When the user logs in using the second form, the account is associated with ReadWriteRole. Once the user logs in, they see a screen where they can see and enter to-do tasks. Users who log in with the ReadOnlyRole will not be able to enter new tasks, while the other ones can create new to-do items. Please follow the instructions below to configure and run the example. The complete source code of the example is available in the Backendless GitHub account.

  1. Open Backendless Console to create a new application or select an existing one.
  2. Click the “Users” icons in the vertical menu on the left and select the “User Properties” section to adjust the properties. In this application we will use the “name” property as the identity:
  3. The next step is to define the roles for the application. To do that click the “Security & Restrictions” section. You should see a list of the built-in user roles available in the application. Click the “Add Role” button to add two user-defines roles: ReadOnlyRole and ReadWriteRole.

  4. Now create a data table for which we will adjust the role permissions. Go to the Data section and create the ‘Task’ table:
  5. Adjust the table schema by adding the ‘message’ column.
  6. At this point we have two custom user-defined roles and a data table. Now we need to modify the permissions policy between the roles and the data table. To do so, make sure you are in the “Schema and Permissions” screen (Data section). Click the ‘Roles Permissions’ link at the table ‘Schema and Permissions’ view. Override the default permission values so they look as shown in the screenshot below:
  7. Now that the server side is configured, all we need is to copy the application ID and the secret key into the applications’s source code (the values must be pasted into Defaults.java):
  8. Run the app. Use any arbitrary username and password – the app will automatically register the user if an account cannot be found. This is done to simplify the app and show the core of what we wanted to demonstrate without added complexity.
    1. Login to the READWRITEROLE form.
    2. Add a few todo tasks.
    3. Switch to the READROLE form and login there.
    4. You should see a list of tasks created in step B.
    5. Try adding a new tasks – you should see a toast notification informing about the error.

We start a new blog series called “Highlight Reel”. Today Backendless highlight reel comes to you from Irving, Texas. We have a chance to chat with EtherGloo founder Durga Dash about app development and his mobile application “SwarmLocal”.

Thanks for taking the time to chat with us, Durga. So, where are you located?

Irving, Texas

Good to be in neighborhood. Please tell us a little about yourself and your background. What were you doing before?

I did my Masters from Ohio State University in Electrical Engg. Also hold down a full-time job at a software company managing the network infrastructure for their datacenter.

Tell us about the app you have running on Backendless.

SwarmLocal was envisioned during the 2011 Occupy Wall Street protests and then the Arab Spring movements. The goal was to create a service that could leverage the power of the anonymous collective in close proximity by allowing real time communication. Inspired by the behavior of bees in a swarm and hence the name SwarmLocal. To that end the ‘swarms’ in SwarmLocal are mobile and the users anonymous. The app is free and available at AppStore and Google Play.

Cool idea. How long have you been developing apps? Is it your first app?

I have been developing apps for about 5 years. My first two apps were for Windows Mobile. Contraction Timer and BugPhone.

What was the biggest challenge in development?

One of the big challenges in development was being able to broadcast real time audio and video from mobile devices and having a backend that can scale to support it. There are not too many solutions out there currently.

      

Please take us through the process of decision making and options for your applications’ backend.

As far as being able to support broadcasting real time audio and video there not many existing services out there. Especially ones that integrate with native code on the different end user devices.

How did you come across Backendless BaaS platform?

I was attending a mobile developers meetup in Dallas and one of the presenters was Mark Piller. He did a presentation on Backendless backend as a service. I was at that time looking for a solution that would do the heavy lifting on the backend and let me focus on the user front end, so Backendless seemed like a perfect fit for my needs.

What Backendless features do you use in your application?

Currently we use the media services API to broadcast real-time audio and video from iOS devices.

What do you like the most in Backendless as a Backend as a Service platform?

  • Easy and elegant administration panel;
  • Well documented API’s and examples;
  • I was able to reach out to Backendless support and even make feature requests which were added pretty quickly;
  • At the end of the day it is very simple to use. And I like to use tools that make it really simple and do the heavy stuff behind the scenes.

Which issues do you expect to be covered by Backendless for you in the future?

From my perspective, I would like to see the Media Services API extended to more platforms and not just iOS. Also the ability to manipulate live streams to add/insert custom content from the admin panel.

What are your plans for the future?

  • Allow live streaming across multiple mobile platforms.
  • Give users the ability to encrypt their messages.
  • Spread out to other platforms, beyond iOS and Android.

What do you do when you aren’t busy working? Any favorite hobbies?

I have a three year old daughter who is a time sink. Other than that working on SwarmLocal and my new passion for boxing.

Do you have any advice for people who create their first apps?

I did write a blog that I hope will help other indie developers on their journey to writing their first app. It can be found here.

Well, best wishes, Durga. We appreciate sharing your thoughts with us.

P.S. If you have a production app running on Backendless, please drop us a line at community@backendless.com. We will be glad to present you in our highlight reel.

A quick heads-up for everyone – we just opened up a discussion forum available at: https://backendless.com/product/forum/.

The rule of thumb is to use the Community Support site for bug reports, feature and improvement suggestions and the use the forum for all other conversations.

 

Posted in Status

In this write-up we review a JavaScript application we recently ported to Backendless. The application is an “editable invoice” which automatically saves its data including invoice line items, customer address, your own address, invoice number, etc. It is a good example demonstrating how to work with “related persistent data”, which means you can save a hierarchy or objects containing other objects (the “Invoice” object, contains a collection of “Line Items”). The application also demonstrates the functionality of user registration and login, although we stopped short of connecting the invoices with the user accounts (which would be fairly simple to add).

The Editable Invoice application is an effort by noBackend.org which helps educating the developers about the advantages of BaaS. The vision is to provide a reference implementation with various backends.

The source code for the application has been push to our Github account.

Follow the steps below to setup and see the application in action:

  1. Register/login to the Backendless console. An application is created during the registration process or you can create one later at any time.
  2. Select an application once you login to console.
  3. Click the Manage icon. The App Settings screen will open up. The screen contains many useful settings and properties, but for now you will need only the Application ID and the Secret Key for the JavaScript clients.
  4. Keep the browser window open (you will need to copy/paste the ID and the Key from that screen) and open /editable-invoice/backendless/applogic.js in a text editor.
  5. Copy/paste the Application ID and Secret Key into the code on line 1:
  6. There is only one additional configuration step needed before you can run the application. Click the Users icon in the Backendless Console. The “User Properties” screen will open by default. Using this screen you can define the user properties which will be used by the Editable Invoice app. Click the “Add Custom Property” button and add the “login” property.
  7. Click “Save”. Make sure to select the “login” property as “Identity” by selecting the radio button for that property. The User Properties screen should look as shown below:
  8. Run the example. You can open the editable-invoice/index.html in a browser directly from the file system. Alternatively, you can deploy the entire application to a web server and load editable-invoice/index.html through a URL.

Try the following once you run the application:

  • Modify the invoice name by changing the main header at the top.
  • Modify the “Your Address” field.
  • Modify the “Your client’s address” field.
  • Add a new item to the invoice – enter item code, description, unit price and quantity. Click the “Add item” button.
  • Reload the application – you should see the invoice you just modified.
  • Check out the Sign Up/Sign In forms.
  • Login to Backendless Console and check the registered users in Data > Users, as well as data stored by the application in the “invoice” and “item” tables – the tables will be created automatically once you start using the example.

Reviewing Code

Below you will find some of the examples of using the Backendless API in the application:

  • Loading all invoices upon the start of the application. (/backendless/applogic.js, lines 3-15)

    Line 5 obtains a reference to the “invoices” data store in Backendless. The returned object provides access to the CRUD (Create, Retrieve, Update, Delete) operations for that table.
    Line 8 (find) sends a request to load all the previously saved invoice objects.
    Lines 10-13 request that the invoice objects returned by Backendless included references to the related “items” objects (an Invoice contains line items or just “items”).
  • Saving/Updating an Invoice. (/backendless/applogic.js, lines 39-62)

    Lines 3-7: check if the invoice has been previously saved. Uses the “condition” parameter where it specifies to search for the invoice by the “id” property.
    Lines 10-19: if the invoice is found (i.e. it has been previously saved), iterate through the items and assign the item’s “objectId”. In this example each “item” has an “id” assigned on the client-side (/shared/js/invoice.js, lines 14 and 28). On top of this, Backendless assigns its own ID to each saved object. That ID is stored in the “objectId” property. It is important to maintain consistency between the objects by correlating the IDs. This block of code accomplishes it for the save operation.
    Line 22: once the IDs are assigned, the entire invoice (with all the items) is saved.
  • Deleting an Invoice. (/backendless/applogic.js, lines 64-68)
  • User Registration. (/backendless/applogic.js, lines 82-93)

    Lines 2-5: Create a Backendless.User object which contains the values for all the user properties defined in step 7 above.
    Lines 6-11: Send a request to Backendless to register the user. The request is asynchronous with the Backendless.Async object handling the callbacks for success and error functions.
  • User Login. (/backendless/applogic.js, lines 94-104)

    Line 2: Send a login request to Backendless. The first argument must be a value for the property defined as “Identity” (see step 7 above).
Posted in Examples, JavaScript

Video broadcasting and streaming is one of the coolest features of Backendless. Our Media Service API enables client-server functionality for working with live and on-demand audio and video content. An application using the Media Service API can broadcast audio and video from the devices cameras and microphone and Backendless automatically handles streaming to other clients as well recording of the content on the server. The API also supports the capability to stream the pre-recorded (on-demand) content managed by the Media Service. Details are available in the documentation.

This post describes how to build an iOS application which can record a video on the server and then subsequently play it back. To start, you will need to create a project in XCode:

  1. Goto File->New->Project
  2. Select Single View Application and click Next button
  3. Enter application name for e.g. SimpleVideoService
  4. Choose iPhone device and click next
  5. Choose a location for your project

Now you have a project with single view. A backendless application must be initialized with an ID and a secret key. It can be done in AppDelegate.m:

The values for the APP_ID and SECRET_KEY variables must be obtained from Backendless Console. Login to the console, create/select your application and click the Manage icon. The default subsection is App Settings:

Use the “Copy” buttons to copy the application id value and the secret key for iOS into your code. The copied values must be assigned to the “APP_ID” and “SECRET_KEY” variables accordingly.

Drag and drop view component to your main view:

Change the background for the view:

Add buttons to control the video stream:

Download the Backendless SDK for iOS from http://backendless.com/downloads, unzip it and drag and drop library to your project files:

Also, you need to add the following standard libraries:

  • AudioToolbox.framework
  • AVFoundation.framework
  • CoreData.framework
  • CoreGraphics.framework
  • CoreMedia.framework
  • CoreVideo.framework
  • Libz.dylib
  • Security.framework

Open ViewController.m and import backendless and define the constants as shown below:

Declare the following variables:

Open ViewController.h and declare the *preview property to view the picture from the camera and *playbackView to play the recorded video:

The *preview property needs to be associated with a View. In order to do this select the view component and drag and drop New Referencing Outlet to preview.

This view will be used for the camera. Also we need a view to play the video. Add the “Image View” component and tie it with the *playbackView property.

Now we should create handlers for control the buttons add their signature to ViewController.h:

Add an implementation of the methods in ViewController.m:

Recording Video

On line 3 create an instance of MediaPublishOptions and reference a UI component that will show the video being recorded.

On line 4 we create a publisher. The publisher constructor accepts stream name, a tube name, options and a responder. When the user stops the recording, we check if we are currently publishing a video, then disconnect from the stream and set the publisher and player to nil.

Playing Recorded Video

On line 3 we create an instance of MediaPlaybackOptions and pass in the UI component that will show the recorded video.

On line 4 we create the media player. The constructor accepts a stream name, a tube name, options and the responder. Since the responder is set to self, the ViewController class must implement IMediaStreamerDelegate.

As we implement IMediaStreamerDelegate we should add the following code to handle stream state changes:

 Everything is almost ready, just link the buttons with the handlers:

Repeat the same for other buttons.

That’s all, enjoy :)

You can download the sample code here.

Posted in Examples, iOS

The Backendless API for JavaScript can be used not only from the browser-based JavaScript applications, but also from a Node.js program. Using the API is very straight-forward. The instructions below describe the steps for setting up and running a basic Node.js example with Backendless. The example demonstrates registering a user with your Backendless application. It gathers email address and password and uses the User Registration API call to create an account.

  1. Just like with the browser JavaScript, an application must be identified using the application ID and a secret key. To get the ID and the key, login to the Backendless console, create/select your application and click the Manage icon. The default subsection is App Settings:
  2. Save the code shown below into a file. Name the file example.js.
  3. Use the “Copy” buttons to copy the application id value and the secret key for JavaScript. The copied values must be assigned to the “appId” and “secretKey” variables accordingly.
  4. Download the Backendless JavaScript library file and save it in the same directory where you created example.js (step 2).
  5. Open a command prompt window and run the example using the following command:
    node example.js

The source code of the example is below (double-click the code to remove the highlighting, or click the <> button to toggle it):

Have fun and please let us know if you run into any problems!

Developing JavaScript applications with a backend-as-a-service platform like Backendless significantly simplifies and speeds up the development process. With the latest release of our SDK for JavaScript, this equally applies to both mobile and browser-based apps as well as Node.js applications. The video below reviews the available APIs and demonstrates sample applications showing the simplicity, ease-of-use and the power of Backendless services. Enjoy!

Posted in JavaScript, Video

We have just updated our JavaScript library enabling API access to the Backendless services. The update includes support for Node.js applications as well as several bug fixes. The SDK is available for download in the downloads section of the website. Additionally, if you develop JS applications, you can always import the latest version of the Backendless JavaScript library using the following URLs:

Please let us know about any problems or if you have any suggestions, post them to the Backendless Community Support site.

Posted in JavaScript