X

EMEA A&C CCOE Partner Technology Cloud Engineering

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

Join the discussion

Comments ( 2 )
  • TreeStrepek Wednesday, August 20, 2014

    Thank You Jernej Kaše.

    This is the most complete blog post on the Push Notification process. Your GitHUB link doesn't work for me? Can you provide more information on how I can get the complete code for the 2nd JAVA App please? This is part of the process which is too ambiguous for a newbee developer like me.

    Working Hard to Figure this Out!

    TreeStrepek


  • TreeStrepek Wednesday, August 20, 2014

    2nd of 2: Here's the error I am getting.

    MacBook-Pro-3$ git clone git://java.net/imc-demos~source

    Cloning into 'imc-demos~source'...

    fatal: Unable to look up java.net (port 9418) (nodename nor servname provided, or not known)


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.