Lists of the most common errors and solutions (Part 4)

Issue #1 After the Bridging-Header.h file was created. I tried to run my build but it failed with the following error message

/Users/mcj/Dev/PaleoRecipes/PaleoRecipes/PaleoRecipes-Bridging-Header.h:10:9: error: ‘CDTDatastore/CloudantSync.h’ file not found
#import <CDTDatastore/CloudantSync.h>
^
<unknown>:0: error: failed to import bridging header ‘/Users/mcj/Dev/PaleoRecipes/PaleoRecipes/PaleoRecipes-Bridging-Header.h’

Solution

1.   Check at your Bridging-Header.h file and to make sure that the import statement for the file not found is there.

#import <Foundation/Foundation.h>
#import <CDTDatastore/CloudantSync.h>
#import <CloudantToolkit/CloudantToolkit.h>
#import <IMFCore/IMFCore.h>
#import <IMFPush/IMFPush.h>
#import <facebookSDK/FacebookSDK.h>
#import “IMFFacebookAuthenticationHandler.h”
#import <IMFData/IMFData.h

2.   Check your Xcode project environment setting for deployment target. In my case, I have two targets build configuration PaleoRecipes and PaleoRecipesTests. if you look at my PaleoRecipesTests target build configuration it’s currently set to “None” and this is the root cause of why my build was failing.

PaleoRecipes_xcodeproj (1)

3.   To get rid of this error message. If you want to use the Pods on both targets like I do, I had to set my build configuration to Pods.debug and Pods.release. If you rebuild your project again this error should go away.

PaleoRecipes_xcodeproj

Advertisements

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

Member_Center_-_Apple_Developer

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

Add_-_iOS_Certificates_-_Apple_Developer

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

Add_-_iOS_Certificates_-_Apple_Developer_and_Keychain_Access

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

Keychain_Access_and_IBM_MobileFirst_Platform_for_iOS_on_Bluemix_6_docx

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

Keychain_Access

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

Push_Dashboard

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

Screenshot_8_19_15__3_57_PM

9.1.6 Allow Push Notification > Select Yes

Screenshot_8_19_15__3_36_PM

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)