Creating a high-powered iOS apps with Bluemix (Part 3)

Part 3: Instrument the Client App

In this section of the tutorial, we will be instrumenting the client application so we can start recording data for monitoring and gather user statistics about the client mobile application usage in the IBM Advanced Mobile Access dashboard. Once that is done, we will move on to how to setup the Push iOS 8 notification to use the Apple Push Notification (APN) services. We will subscribe to notification tags and run our tests to confirm that the push notification message is successfully delivered to our end users.

6. Instrument the client Application for App Monitoring

We will be instrumenting the client application so we can start recording data for monitoring and gather user statistics about the client mobile application usage and view it in the Bluemix dashboard.

6.1 Enable the logging and Analytics and view it in the Bluemix dashboard. First, we must send log data to the server by copying the following function to the AppDelegate.swift file.

func applicationDidEnterBackground(application: UIApplication) {

// Consider if these calls should be in applicationDidEnterBackground and/or other application lifecycle event.

// Perhaps [IMFLogger send]; should only happen when the end-user presses a button to do so, for example.

// CAUTION: the URL receiving the uploaded log and analytics payload is auth-protected, so these calls

// should only be made after authentication, otherwise your end-user will receive a random auth prompt!

IMFLogger.send() // send all IMFLogger logged data to the server

IMFAnalytics.sharedInstance().sendPersistedLogs() // send all analytics data to the server


6.2 Set debug levels by calling the IMFLogger setLevel Function. For this tutorial we will set the IMFLogger to enable crash capture.

6.2.1 copying the following code to func applicaton(application: UIApplication, didFinishLaunchingWithOptions launchOptions:NSDictionry in the swift file

//Analytics and Monitoring

IMFLogger.captureUncaughtExceptions() // capture and record uncaught exceptions (crashes)

6.3 Capture logs from your application only and exclude logger entries from the IBM MobileFirst SDK codebase. In order to do that, we need to set the filter on the IMFLogger to allow login only for your package AppDelegate.swift file

6.3.1 Set the IMFLogger, add the following lines of code right after step 6.2.1

IMFLogger.setLogLevel(IMFLogLevel.Error) // setting the verbosity filter. Change to Info to get more logging output

IMFAnalytics.sharedInstance().startRecordingApplicationLifecycleEvents() // automatically record app startup times and foreground/background events

logger = IMFLogger(forName: “yourAppName”)

6.4 Run your test for the App Monitoring by launching your app by clicking on the run button from your project navigator and then switch to your Bluemix dashboard > Advanced Mobile Access. You should be able to view the device logs, Authentication, etc directly from the Bluemix Dashboard

Mozilla_Firefox (1)

7. Setting up Push iOS 8 Notification

To use the Apple Push Notification (APNs) services, we will need an SSL certification, which is required for each environment (sandbox and production). The certificates that are needed for APNs are .p12 certificates. If you haven’t generated your certificates already, you will need to log on to the Member Center of the Apple Developer Website and then generate your SSL Certification.

7.1 Configuring for Apple Push Notification (APN) service

An SSL certification is required for each environment. We will need to obtain the certificates from the Member Center of the Apple Developer

7.1.1 Bring up your web browser and go to the Apple Developer Website

7.1.2 Go to > Certificates, Identifiers & Profiles


7.1.3 Click > Certificates > Development> Add > iOS App Development > Next


7.1.4 Create a Certificate Signing Request (CSR) file

Please see all the steps on how to manually create a CSR file in the screenshot down below. Once the CSR file is successfully created Click > Continue

Add_-_iOS_Certificates_-_Apple_Developer (1)

7.1.5 Generate your certificate

Upload a CSR file that was previously created in step 7.1.4 and then Click > Generate


7.1.6 Download this certificate to your computer

Add_-_iOS_Certificates_-_Apple_Developer (2)

7.1.8 Go to Identifier Section > Create an App ID > Check Push Notification for Development SSL Certification then Click Create Certificate and then save it to your computer. You will need this certificate in order to create the .p12 file

7.1.9 Go to Devices Section and register device. You will need to the UUID of your iOS device.

The UUID is unique device identifier that was assigned to each iOS device. To get the UUID, bring up the iTunes Application > Select your iOS device > Summary > Click on Serial number until you see that it switches to UUID

To copy UUID, go to Edit > Copy UUID

7.1.10 Go to Provisioning Profiles section and create a profile for development and download it to you computer

7.1.11 Double Click on the .cer file that you have just download

7.1.12 From Keychain Access > select Key and look for the profile name that you have created in step 7.1.4 and 7.1.5

7.2 Generate .p12 file

7.2.1 Double click on the .cer file that you have just download from step 7.1.10

7.2.2 Applications > Utilities > Keychain Access > Key look for the profile name that you created in step 7.1.4 and 7.1.5

7.2.3. Expand Private Key profile and you should see the certificate file that you just added


7.2.4 Select both the private key and certificate > click “Export 2 item” and make sure that you save the file formate to .p12 file


7.3 Configure the Push iOS 8 Notification in Bluemix

7.3.1 Bring up a browser and bring up your Bluemix Project Dashboard

Dashboard_-_IBM_Bluemix (3)

7.3.2 Click the Push iOS notification > Configuration > sandbox

7.3.3 Upload the SSL Certificate (.p12) that we previously create to Bluemix then click > Save


7.3.4 Click on Tags > CREATE TAG, enter a tag name “Push Notification” then click SAVE

Push_Dashboard (1)

8. Set up the iOS development for Push iOS 8 notification

From your xc.workspace, Open your <appName>.plist and validate the applicationId, applicationRoute and update the applicationSecret and variables to match the identity provided by the IBM Bluemix for Push iOS 8 notification.

Note: If you are getting the following error message

2015-08-19 14:20:43.471 PaleoRecipes[4388:1842585] You’ve implemented -[<UIApplicationDelegate> application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add “remote-notification” to the list of your supported UIBackgroundModes in your Info.plist.

  • From the Project Navigator > click the project
  • Select > Targets then Click> Capabilities tab
  • Expand and turn on Background Modes
  • Select > Remote Notification

PaleoRecipes_xcodeproj (2)

9. Running Test for the push notification

Next we want to make sure that the push notification is working from the client application and from the Bluemix Dashboard. We want to manually push the message from the Bluemix application to all of the registered devices and validate that our message will get through.

9.1 Testing for the notification from the Xcode project

Note: This can’t be done via an iOS simulator. You will need to connect the iOS device into your machine to run the test.

9.1.1 Connect the iOS device into your machine

9.1.2 From Xcode > Select the device from the drop-down list

9.1.3 Select your application under the Targets make sure that there is no warning or error message regarding the code signing

9.1.4 Switch to the Building setting tab, search for provisioning profile and make sure that you are selecting the provisioning profile that you created from section 7.1.10

PaleoRecipes_xcodeproj (1)\

9.1.5 Run the app, when app starts, click on setting Screenshot_8_19_15__3_53_PM icon and slide the switch to turn on Notifications and subscribe to the subscription tag that you had previously created in step 7.2.4


9.1.6 Allow Push Notification > Select Yes


9.2 Manually Push Notification from the Push Notification Dashboard

Note: To see the push notification message that you will send to your iOS device, from your iOS device, press home button and put the app in the background.

9.2.1 Go to Notifications > SEND NOTIFICATION > select All registered mobile devices > Next

9.2.2 Type in Message Text “Push notification ” > SEND

Push_Dashboard (3)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s