SlideShare a Scribd company logo
1 of 25
Download to read offline
How do I?
Use Push Notification
What’s Push?
✦Originally iOS didn’t allow processes to run in the
background (it’s still pretty hard there)
✦Push lets the server notify the user about an update
✦Mostly a visual notification, badge or message
✦It’s different on Android, but we try to “normalize” that
✦Push can be disabled by the user & won’t be available
on Kindle where Google play services aren’t available
© Codename One 2017 all rights reserved
How does it work?
✦Each OS has a radically different implementation
of push
✦We have our own servers that mitigate that by
exposing a unified web service call for iOS,
Android, Windows, Chrome & Firefox
✦We still need credentials to work with each one of
the server types I’ll cover only iOS & Android for
simplicity
© Codename One 2017 all rights reserved
public class MainClass implements PushCallback {
public void init(Object context) {
// …
}
public void start() {
// …
Display.getInstance().callSerially(() ->
Display.getInstance().registerPush());
}
public void push(String value) {
// …
}
public void registeredForPush(String deviceId) {
}
public void pushRegistrationError(String error, int errorCode) {
Log.p("Push registration failed: " + error);
}
Push Callback
Push Callback
public class MainClass implements PushCallback {
public void init(Object context) {
// …
}
public void start() {
// …
Display.getInstance().callSerially(() ->
Display.getInstance().registerPush());
}
public void push(String value) {
// …
}
public void registeredForPush(String deviceId) {
}
public void pushRegistrationError(String error, int errorCode) {
Log.p("Push registration failed: " + error);
}
Push Callback
public class MainClass implements PushCallback {
public void init(Object context) {
// …
}
public void start() {
// …
Display.getInstance().callSerially(() ->
Display.getInstance().registerPush());
}
public void push(String value) {
// …
}
public void registeredForPush(String deviceId) {
}
public void pushRegistrationError(String error, int errorCode) {
Log.p("Push registration failed: " + error);
}
Sending Push
✦ From another mobile device you can use the
Push class
✦ From a server send a standard POST request as
explained in the developer guide
© Codename One 2017 all rights reserved
Send Push
HttpURLConnection connection = (HttpURLConnection)new URL("https://
push.codenameone.com/push/push").openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-
urlencoded;charset=UTF-8");
String query = "token=" + PUSH_TOKEN +
"&device=" + URLEncoder.encode(deviceId, "UTF-8") +
"&type=" + type +
"&auth=" + URLEncoder.encode(GCM_SERVER_API_KEY, "UTF-8") +
"&certPassword=" + URLEncoder.encode(pass, "UTF-8") +
"&cert=" + URLEncoder.encode(cert, "UTF-8") +
"&body=" + URLEncoder.encode(messageBody, "UTF-8") +
"&production=" + ITUNES_PRODUCTION_PUSH;
try (OutputStream output = connection.getOutputStream()) {
output.write(query.getBytes("UTF-8"));
}
int c = connection.getResponseCode();
Types of Push Messages
✦Other types are available for special cases
✦0 or 1 - The default push. It will appear as a visible
message to the user
✦2 - invisible push, doesn’t show any UI and only invokes
the push method. Will not work in the background in iOS
✦3 - Combines 1 and 2 into a single bundled message.
When a visual message is clicked you receive it & the
hidden message
Troubleshooting Push
✦Try push from the simulator, check the network
inspector to verify the request/response
✦Inspect the JSON result, it should include error
messages if there is a problem
✦For iOS push make sure the certificate are accessible
as a file and not as a page with a download button
✦Verify production/sandbox modes in iOS. IOS devices
take 24hr to switch between production & sandbox
© Codename One 2017 all rights reserved
Thank You!

More Related Content

Similar to How do I - Use Push Notification.pdf

WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsWebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
Robert Nyman
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
Simon Su
 
Building a chat app with windows azure mobile
Building a chat app with windows azure mobileBuilding a chat app with windows azure mobile
Building a chat app with windows azure mobile
Flavius-Radu Demian
 

Similar to How do I - Use Push Notification.pdf (20)

Cross-Platform Authentication with Google+ Sign-In
Cross-Platform Authentication with Google+ Sign-InCross-Platform Authentication with Google+ Sign-In
Cross-Platform Authentication with Google+ Sign-In
 
The Future of Progressive Web Apps - Google for Indonesia
The Future of Progressive Web Apps - Google for IndonesiaThe Future of Progressive Web Apps - Google for Indonesia
The Future of Progressive Web Apps - Google for Indonesia
 
Cgi
CgiCgi
Cgi
 
Building Creative Product Extensions with Experience Manager
Building Creative Product Extensions with Experience ManagerBuilding Creative Product Extensions with Experience Manager
Building Creative Product Extensions with Experience Manager
 
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
How React Native, Appium and me made each other shine @ContinuousDeliveryAmst...
 
WebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.jsWebAPIs & WebRTC - Spotify/sthlm.js
WebAPIs & WebRTC - Spotify/sthlm.js
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
 
Building Creative Product Extensions with Experience Manager
Building Creative Product Extensions with Experience ManagerBuilding Creative Product Extensions with Experience Manager
Building Creative Product Extensions with Experience Manager
 
Building a chat app with windows azure mobile
Building a chat app with windows azure mobileBuilding a chat app with windows azure mobile
Building a chat app with windows azure mobile
 
A gently introduction to AngularJS
A gently introduction to AngularJSA gently introduction to AngularJS
A gently introduction to AngularJS
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php Security
 
How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server How to build a High Performance PSGI/Plack Server
How to build a High Performance PSGI/Plack Server
 
Puppeteer can automate that! - HolyJS Piter 2020
Puppeteer can automate that! - HolyJS Piter 2020Puppeteer can automate that! - HolyJS Piter 2020
Puppeteer can automate that! - HolyJS Piter 2020
 
Php security
Php securityPhp security
Php security
 
Mobile Web on Touch Event and YUI
Mobile Web on Touch Event and YUIMobile Web on Touch Event and YUI
Mobile Web on Touch Event and YUI
 
Vaadin 7
Vaadin 7Vaadin 7
Vaadin 7
 
Hybrid app
Hybrid appHybrid app
Hybrid app
 
Puppeteer can automate that! - Frontmania
Puppeteer can automate that! - FrontmaniaPuppeteer can automate that! - Frontmania
Puppeteer can automate that! - Frontmania
 
Windows Azure: Connecting the Dots for a Mobile Workforce
Windows Azure: Connecting the Dots for a Mobile WorkforceWindows Azure: Connecting the Dots for a Mobile Workforce
Windows Azure: Connecting the Dots for a Mobile Workforce
 
Connecting to a Webservice.pdf
Connecting to a Webservice.pdfConnecting to a Webservice.pdf
Connecting to a Webservice.pdf
 

More from ShaiAlmog1

More from ShaiAlmog1 (20)

The Duck Teaches Learn to debug from the masters. Local to production- kill ...
The Duck Teaches  Learn to debug from the masters. Local to production- kill ...The Duck Teaches  Learn to debug from the masters. Local to production- kill ...
The Duck Teaches Learn to debug from the masters. Local to production- kill ...
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
create-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdfcreate-netflix-clone-01-introduction_transcript.pdf
create-netflix-clone-01-introduction_transcript.pdf
 
create-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdfcreate-netflix-clone-02-server_transcript.pdf
create-netflix-clone-02-server_transcript.pdf
 
create-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdfcreate-netflix-clone-04-server-continued_transcript.pdf
create-netflix-clone-04-server-continued_transcript.pdf
 
create-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdfcreate-netflix-clone-01-introduction.pdf
create-netflix-clone-01-introduction.pdf
 
create-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdfcreate-netflix-clone-06-client-ui_transcript.pdf
create-netflix-clone-06-client-ui_transcript.pdf
 
create-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdfcreate-netflix-clone-03-server.pdf
create-netflix-clone-03-server.pdf
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
create-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdfcreate-netflix-clone-05-client-model_transcript.pdf
create-netflix-clone-05-client-model_transcript.pdf
 
create-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdfcreate-netflix-clone-03-server_transcript.pdf
create-netflix-clone-03-server_transcript.pdf
 
create-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdfcreate-netflix-clone-02-server.pdf
create-netflix-clone-02-server.pdf
 
create-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdfcreate-netflix-clone-05-client-model.pdf
create-netflix-clone-05-client-model.pdf
 
Creating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdfCreating a Whatsapp Clone - Part II.pdf
Creating a Whatsapp Clone - Part II.pdf
 
Creating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdfCreating a Whatsapp Clone - Part IX - Transcript.pdf
Creating a Whatsapp Clone - Part IX - Transcript.pdf
 
Creating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdfCreating a Whatsapp Clone - Part II - Transcript.pdf
Creating a Whatsapp Clone - Part II - Transcript.pdf
 
Creating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdfCreating a Whatsapp Clone - Part V - Transcript.pdf
Creating a Whatsapp Clone - Part V - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdfCreating a Whatsapp Clone - Part IV - Transcript.pdf
Creating a Whatsapp Clone - Part IV - Transcript.pdf
 
Creating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdfCreating a Whatsapp Clone - Part IV.pdf
Creating a Whatsapp Clone - Part IV.pdf
 
Creating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdfCreating a Whatsapp Clone - Part I - Transcript.pdf
Creating a Whatsapp Clone - Part I - Transcript.pdf
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

How do I - Use Push Notification.pdf

  • 3. What’s Push? ✦Originally iOS didn’t allow processes to run in the background (it’s still pretty hard there) ✦Push lets the server notify the user about an update ✦Mostly a visual notification, badge or message ✦It’s different on Android, but we try to “normalize” that ✦Push can be disabled by the user & won’t be available on Kindle where Google play services aren’t available © Codename One 2017 all rights reserved
  • 4. How does it work? ✦Each OS has a radically different implementation of push ✦We have our own servers that mitigate that by exposing a unified web service call for iOS, Android, Windows, Chrome & Firefox ✦We still need credentials to work with each one of the server types I’ll cover only iOS & Android for simplicity © Codename One 2017 all rights reserved
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18. public class MainClass implements PushCallback { public void init(Object context) { // … } public void start() { // … Display.getInstance().callSerially(() -> Display.getInstance().registerPush()); } public void push(String value) { // … } public void registeredForPush(String deviceId) { } public void pushRegistrationError(String error, int errorCode) { Log.p("Push registration failed: " + error); } Push Callback
  • 19. Push Callback public class MainClass implements PushCallback { public void init(Object context) { // … } public void start() { // … Display.getInstance().callSerially(() -> Display.getInstance().registerPush()); } public void push(String value) { // … } public void registeredForPush(String deviceId) { } public void pushRegistrationError(String error, int errorCode) { Log.p("Push registration failed: " + error); }
  • 20. Push Callback public class MainClass implements PushCallback { public void init(Object context) { // … } public void start() { // … Display.getInstance().callSerially(() -> Display.getInstance().registerPush()); } public void push(String value) { // … } public void registeredForPush(String deviceId) { } public void pushRegistrationError(String error, int errorCode) { Log.p("Push registration failed: " + error); }
  • 21. Sending Push ✦ From another mobile device you can use the Push class ✦ From a server send a standard POST request as explained in the developer guide © Codename One 2017 all rights reserved
  • 22. Send Push HttpURLConnection connection = (HttpURLConnection)new URL("https:// push.codenameone.com/push/push").openConnection(); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/x-www-form- urlencoded;charset=UTF-8"); String query = "token=" + PUSH_TOKEN + "&device=" + URLEncoder.encode(deviceId, "UTF-8") + "&type=" + type + "&auth=" + URLEncoder.encode(GCM_SERVER_API_KEY, "UTF-8") + "&certPassword=" + URLEncoder.encode(pass, "UTF-8") + "&cert=" + URLEncoder.encode(cert, "UTF-8") + "&body=" + URLEncoder.encode(messageBody, "UTF-8") + "&production=" + ITUNES_PRODUCTION_PUSH; try (OutputStream output = connection.getOutputStream()) { output.write(query.getBytes("UTF-8")); } int c = connection.getResponseCode();
  • 23. Types of Push Messages ✦Other types are available for special cases ✦0 or 1 - The default push. It will appear as a visible message to the user ✦2 - invisible push, doesn’t show any UI and only invokes the push method. Will not work in the background in iOS ✦3 - Combines 1 and 2 into a single bundled message. When a visual message is clicked you receive it & the hidden message
  • 24. Troubleshooting Push ✦Try push from the simulator, check the network inspector to verify the request/response ✦Inspect the JSON result, it should include error messages if there is a problem ✦For iOS push make sure the certificate are accessible as a file and not as a page with a download button ✦Verify production/sandbox modes in iOS. IOS devices take 24hr to switch between production & sandbox © Codename One 2017 all rights reserved