Author: Christos Vasilakis (cvasilak)
Level: Intermediate
Technologies: Objective-C, iOS
Summary: The push-contacts-mobile-ios
quickstart demonstrates how to develop a contacts CRUD iOS application with push notification integration.
Target Product: JBoss Unified Push
Versions: 1.0
Source: https://github.com/jboss-developer/jboss-mobile-quickstarts/
The push-contacts-mobile-ios
quickstart demonstrates how to develop more advanced iOS push applications, centered around a CRUD contacts application.
This client-side iOS project must be used in conjunction with the push-contacts-mobile/server/push-contacts-mobile-picketlink-secured
application, which provide the accompanying server-side functionality.
When the client application is deployed to an iOS device, the push functionality enables the device to register with the running JBoss Unified Push Server OpenShift instance and receive push notifications. The server-side application provides login authentication for the client application and sends push notification requests to the JBoss Unified Push Server OpenShift instance in response to new contacts being created. Push notifications received by the iOS device contain details of newly added contacts.
- iOS 7.X
- Xcode version 5.1.X
First you need to submit a request for a new digital certificate, which is based on a public/private key. The Certificate itself is acting as the public key, and when you request it, a private key is added to your KeyChain
tool. The Cerficate will be used later on, to request an SSL certificate for the Apple Push Network Service
, which will allow the JBoss Unified Push Server to send notification messages to it.
- Request a new CSR (Certificate Signing Request) using
KeyChain Access
tool found inApplications > Utilities
folder on your Mac. Once opened, in theKeyChain Access
menu, chooseCertificate Assistant > Request a Certificate from a Certificate Authority
. Make sure that you have choosen to store the CSR on file, so we can upload it later in the provisioning portal when requesting the actual SSL cert. - Go to the Provisioning Portal and log in with your Apple developer account. Now, click on the
Identifiers
link in order to create a newApp ID
(use thePLUS
Icon on the right). In the formular give theApp ID
a descriptive name. Double check that thePush Notifications
checkbox is selected. - Later in the same page you are asked for an
Explicit App ID
, since the genericWildcard App ID
does not work with Push Notifications. In theBundle ID
field enter YOURBundle ID
. This is similar to Java packages. NOTE: TheBundle ID
has to match the one from the actual iOS application that you are building later in this guide. - In the next screen confirm your new
App ID
, and double check that thePush Notifications
option is enabled. Afterwards click theSubmit
button. In the next screen, click on on the newly createdApp ID
, then click theEdit
button and scroll down to thePush Notifications
section. Here we are asked to generate aDevelopment
and aProduction
certificate that will be used by the JBoss Unified Push Server when contacting the Apple Push Notification service to send messages. If you plan to distribute your app in the App Store, you are required to generate a Production certificate.
Development Certificate
: Click theCreate Certificate
button on theDevelopment SSL Certificate
section. Upload theCertificate Signing Request
that you created earlier and click theGenerate
button. TheDevelopment SSL Certificate
file is being downloaded asaps_development.cer
.Production Certificate
: Click theCreate Certificate
button on theProduction SSL Certificate
section. Upload theCertificate Signing Request
that you created earlier and click theGenerate
button. TheProduction SSL Certificate
file is being downloaded asaps_production.cer
.
You have to export this certificates/private keys pair to the .p12 (Personal Information Exchange). These files will be uploaded later on to the JBoss Unified Push Server enabling it to authorize themselves for your development application on Apple Push Network Service and send messages to them. When exporting the files, as your private keys, you need to assign a passphrase for them. Make note of them, because later when uploading them to the JBoss Unified Push Server you will need both the exported files (aps_development.cer
, aps_production.cer
) and the passphrases.
In order to test Push Notifications you neeed to create a Provisioning Profile.
Development Provisioning Profile
: In the Provisioning Portal you need to create an iOS App Development provisioning profile, so that you can test the Push Notifications on your own iOS devices. Select theApp ID
that you created earlier and your Developer Certificate. Select a Test Device, give it a Profile Name and generate it. Now download the Profile and open the file. Go toXcode -> preferences...
menu, select theAccount
tab, on the right bottom corner clickView details...
and you should see your provisioning profile.Distribution Provisioning Profile
: In order to test Push Notifications on aproduction environment
, you need to create an iOS App Distribution provisioning profile in the Provisioning Portal. Select theApp ID
, that you created earlier and your Production Certificate. You still need a test device to try your production app with your distribution provisioning profile. Select a Test Device, give it a Profile Name and generate it. Now download the Profile and open the file. Go toXcode -> preferences...
menu, select theAccount
tab, on the right bottom corner clickView details...
and you should see your provisioning profile.
You must register the application and an iOS variant of the application with the JBoss Unified Push Server. This requires a running JBoss Unified Push Server OpenShift instance and uses the unique metadata assigned to the application by APNS. For more information about deploying, configuring and using the JBoss Unified Push Server, see the JBoss Unified Push documentation and JBoss xPaaS Services for OpenShift.
- Log into the JBoss Unified Push Server OpenShift instance console.
- In the
Applications
view, clickCreate Application
. - In the
Name
andDescription
fields, type values for the application and clickCreate
. - When created, under the application click
No variants
. - Click
Add Variant
. - In the
Name
andDescription
fields, type values for the iOS application variant. - Click
iOS
and type the values assigned to the project by APNS (you will have to upload your Developer or Production Certificate) - Click
Add
. - When created, expand the variant name and make note of the
Server URL
,Variant ID
, andSecret
.
Replace the bundleId with your bundleId (the one associated with your certificate).
Click on the Contacts target -> General
and modify the Bundle Identifier:
Ensure the Apple Provisioning profile is correctly set:
The project source code must be customized with the unique metadata assigned to the application variant by the JBoss Unified Push Server and APNS.
-
Open
QUICKSTART_HOME/push-contacts-mobile/client/push-contacts-mobile-ios/Contacts/Controllers/AGLoginViewController.m
for editing. -
Modify the URL, variant and secret to match the values allocated by the JBoss Unified Push Server and APNS for the following constants:
AGDeviceRegistration *registration = [[AGDeviceRegistration alloc] initWithServerURL:[NSURL URLWithString:@"<# URL of the running JBoss Unified Push Server OpenShift instance #>"]]; ... [clientInfo setVariantID:@"<# Variant Id #>"]; [clientInfo setVariantSecret:@"<# Variant Secret #>"];
Note : You can also copy/paste these settings from your JBoss Unified Push Server console
-
Save the file.
-
Open
QUICKSTART_HOME/push-contacts-mobile/client/push-contacts-mobile-ios/Contacts/Networking/AGContactsNetworker.m
for editing. -
Modify the URL to match the path to the Contacts server backend:
static NSString * const kAPIBaseURLString = @"<# URL of the Contacts application backend #>";
-
Save the file.
-
Build the application
- The JBoss Unified Push Server OpenShift instance must be running before the application is deployed to ensure that the device successfully registers with the JBoss Unified Push Server on application deployment.
- The
push-contacts-mobile/server/push-contacts-mobile-picketlink-secured
application must be running before attempting to log into the mobile client application to ensure successful login. For more information, see the README distributed with thepush-contacts-mobile-picketlink-secured
application.
The application can be tested on physical iOS devices only; push notifications are not available for iOS simulators.
When the application is deployed to an iOS device, you can log into it and begin using the CRUD functionality. Note that access to the application is restricted to users registered with the server-side application and to assist you in getting started a number of default users are preconfigured.
-
Launch the application on the iOS device.
-
Log into the application using one of the default user credentials ('maria:maria','dan:dan', or 'john:john').
After successful login, you are presented with a list of existing Contacts residing on the server.
-
Click a contact to open the Edit screen where you can modify the contact's details.
You can send a push notification to your device by creating a new Contact.
You can also send a push notification to your device using the push-contacts-mobile/client/contacts-mobile-webapp
application by completing the following steps (for more information, see the README distributed with the contacts-mobile-webapp
application):
- Open the web interface of the
push-contacts-mobile/client/contacts-mobile-webapp
application in a browser at the following URL: http://localhost:8080/jboss-contacts-mobile-webapp/ . - Add a new Contact.
This automatically triggers a push notification request to the JBoss Unified Push Server OpenShift instance and subsequently the push notification displays on the mobile device.
Instead of the regular didReceiveRemoteNotification
callback invoked when a new notification is received, the application utilizes the 'silent' push feature (offered by iOS 7 and later), so the application can be instructed to fetch the new content even if background (and possible suspended). Thus when the user opens up the app, the content is already available to be viewed. Take a look at the didReceiveRemoteNotification
notification callback method inside the file QUICKSTART_HOME/push-contacts-mobile/client/push-contacts-mobile-ios/Contacts/AGAppDelegate.m
for the implementation details.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
- ...
}
-
Which iOS version is supported by JBoss Unified Push CRUD mobile app?
JBoss Unified Push supports iOS 7.0 and later.
Set a break point in Xcode.