ADF Mobile Push notifications demo on Apple iOS

After the webcast on ADF Mobile, delivered on the 29th of August 2013, I’m going to post the source code for the demos in the next few weeks. 

Starting with the "ADF Mobile Push notifications" demo on Apple iOS.

What do you need

1. JDeveloper 11.1.2.4 with ADF Mobile extension

2. A Mac, Xcode and access to the Apple developer portal

3. Apple push notifications certificate and deployment profile

4. A physical iOS device, as push notification service does not work with the simulator

Documenting how to obtain Apple push notifications certificate is out of scope of this post, but if you search for “apple push notification services certificate” you should find some tutorials that describe the process.

Starting with the mobile application

  1. Create a new ADF Mobile application
  2. In application resources, open Descriptors->ADF META-INF -> adfmf-application.xml
  3. Match the id to your deployment profile application id
  4. While in adfmf-application.xml, you can also select LifeCycleListenerImpl as your application’s Lifecycle Event Listener.
  5. In ApplicationController project, open LifeCycleListenerImpl and implement PushNotificationConfig interface
  6. Add new Java class PushNotificationListener.java which implements EventListener interface
  7. Implement onOpen method as:
  8. ValueExpression ve = AdfmfJavaUtilities.getValueExpression("#{applicationScope.token}", String.class);
    ve.setValue(AdfmfJavaUtilities.getAdfELContext(), token);

    This will store device token, received from the APNS service into the application scope. In real life, we would send this token to our backend (server) app using a Web/REST service.

  9. Return to LifeCycleListenerImpl and implement start() method as:

                  EventSource eventSource=EventSourceFactory.getEventSource(

NativePushNotificationEventSource.NATIVE_PUSH_NOTIFICATION_REMOTE_EVENT_SOURCE_NAME);

eventSource.addListener(new PushNotificationListener());

This will register the application for notifications and configure the listener.

8. The only thing left to do is implementing a feature with a simple amx page that displays the device token stored in #{applicationScope.token}". I’ll leave that part of the exercise to you.



Pushing notifications.

APNS protocol is a bit tricky to handle from scratch, but thankfully there is a java wrapper for it.

Using it implementing a swing application that sends notifications is a breeze. We only need a swing form with 2 input boxes and 2 buttons, potentially we could another one for device token(s).


Implementing the code behind the two buttons is straight forward:

private void jButton1_actionPerformed(ActionEvent e) {

try {

Push.badge(Integer.parseInt(jTextField1.getText()), "/Users/jernej/repo/devservice-ateam_adfmobilewebcast2/ApplePushNotificationTest/pushdemo.p12", "testing123", false,

"8856ce5e08dd75731711e17ff57950860d36119d3666f63bb559644126c1c06a");

} catch (KeystoreException ex) {

JOptionPane.showMessageDialog(null, ex.getMessage());

} catch (CommunicationException ex) {

JOptionPane.showMessageDialog(null, ex.getMessage());

}

}

private void jButton2_actionPerformed(ActionEvent e) {

try {

Push.alert(jTextField2.getText(), "/Users/jernej/repo/devservice-ateam_adfmobilewebcast2/ApplePushNotificationTest/pushdemo.p12", "testing123", false,

"8856ce5e08dd75731711e17ff57950860d36119d3666f63bb559644126c1c06a");

} catch (KeystoreException ex) {

JOptionPane.showMessageDialog(null, ex.getMessage());

} catch (CommunicationException ex) {

JOptionPane.showMessageDialog(null, ex.getMessage());

}

}

The only special thing here is the certificate .p12 file. You get this file through the APNS SSL certificate process. The second parameter (here “testing123”) is the certificate password.

You’ll need to change these two parameters to your file and password in order for the demo to work.

One last note

APNS infrastructure requires a bit liberal network restrictions on the device and on the server. If you are behind a firewall, it might be blocking your outgoing (from the swing application) or incoming (from APNS to the device) connection(s).

Getting the source code

To get the source code for this demo, you need to have git installed on your computer. Once it's up and running simply execute "git clone git://java.net/imc-demos~source" statement from the command line / shell. 

You can see the demo in action here

Happy ADF Mobile coding! 

Stay Connected

Blog Facebook Google Plus YouTube
Twitter Delicious slideshare rss
Oracle Newsletters


Bookmark and Share

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

Oracle ECEMEA Partner Hubs Migration Center Team

We share our skills to maximize your revenue!
Our dedicated team of consultants can rapidly and successfully assist you to adopt and implement the latest of Oracle Technology in your solutions.

Stay Connected
partner.imc
@
beehiveonline.oracle-DOT-com
Google+

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
2
3
4
5
6
9
10
11
12
13
14
16
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today