Push notifications on mobile apps - mobile

OK, how do push notifications work?
I found a nice tutorial: http://lessons.runrev.com/m/4069/l/59312
I get the concept that the device needs to register with the server but does the app essentially hold an AJAX connection to server or does the server somehow plug into the mobile phone network... ?

There are three essential components when talking about push notifications:
Your server
The providers server
Your mobile device
Your server is the sender. It sends the push notification to the providers server, which in turn sends it to the device. Your device, therefore, is the receiver. (Concluding that you don't have to "plug into the mobile phone network", this is all done by your provider - Google in this case)
Within your mobile application you just register an eventhandler which is fired when you receive a push notification.
Google called this C2DM (Cloud to Device Messaging), now GCM (Google Cloud Messaging) - you can get an introduction inclusive of an architectural overview and demos here at android.com.

To answer your question I know:
Both push notifications services (Apple's and Microsoft's) are using a persistent IP connection for implementing their push notifications functionality.
I think Android works the same way (at least with Android Cloud to Device Messaging (C2DM)). "It uses an existing connection for Google services". http://en.wikipedia.org/wiki/Android_Cloud_to_Device_Messaging_Service
But the answer is closer to AJAX, except I assume it is a simple "http" connection to Google Messaging service from Android, and the OS gets an alert of a new message and relays it back to a program that registered on it to want notifications.

Related

How to susbcribe to a telemetry events using MQTT and using C code?

How to susbcribe to a telemetry events using MQTT and using C code? (this is a microcontroller code)
I can send data to a specified topic but when I trying to subscribe to this topic I got error message
This is the message from the log
"mqttTopic": "/devices/my-device/events/my_telem_topic1",
This is the error message from the log
"message": "SUBSCRIBE: Failed to subscribe to topic: '/devices/my-device/events/my_telem_topic1'."
To add to what Kamal posted:
Part of the confusion here is that both MQTT and Pub/Sub (where IoT Core puts your device's telemetry events) are called "topics".
There are 4 MQTT topics for devices to work with (this is all on device side, not Cloud side):
/devices/<device-id>/commands
/devices/<device-id>/config
/devices/<device-id>/state
/devices/<device-id>/events
The first two are there for devices to subscribe to in order to get updates from the IoT Core Admin SDK, the latter two are topics for device to publish data to the Cloud.
In order for a device to subscribe to another device's telemetry, it would need to be able to subscribe to the Pub/Sub topic that's receiving telemetry from the other device. This won't be done as part of the MQTT implementation, but rather, you'd need to implement the Pub/Sub API on your device. This is going to require a separate authentication path as well, likely a service account key that you add to your GCP project, then download to your device. The links in Kamal's answer should get you started if you want to go down that route.
Depending on what you're doing however, as they say, you can probably process the incoming telemetry from one device in a Cloud Function or similar, then set a config for the device that wants to be responsive to that telemetry. That way, if the device is online, it'll get it right away, or if it's not online, it'll get it upon reconnecting to IoT Core.
Telemetry events sent to Cloud IoT are sent to a Cloud Pub/Sub topic that is configured when the device registry is created and are not intended to be retrieved via MQTT on devices. One could use any of the mechanisms available in Google Cloud to subscribe to these messages (Cloud Functions, Cloud Dataflow, or a custom-written subscriber). Commands can be received by devices via MQTT. The topic for a device's commands is /devices/{device-id}/commands/#. APIs are available to send commands to devices.
One would generally send telemetry events from devices, analyze them with one of the aforementioned Cloud products, and then possibly generate commands to devices based on the results of that analysis.

can i use ionic push native without FCM?

so i have a web app and a mobile app, the web app works fine with signalR and SQL, and i'm trying to create an ionic mobile app using the same backend from the web app, so i am a little limited to using signalR as well.
in the web app, i have certain triggers set up to fire popup notifications when certain events occur, and it works great with signalR in the webapp.
the problem is : due to some restrictions i have to use ionic,and i've been searching for 3 days on a way to implement push notifications without having to resort to FCM but i haven't reached anything.
is there a way to do this with ionic 3? to implement push notifications with signalR instead of FCM?
I'm not sure I completely understand your question, but let me see if I can start a dialog.
Ultimately, for push notification, you have to contact both APNS (Apple push notification server) and GCM (Google Cloud Messaging) to enact push notifications on both ios and android phones. So, that means that you can contact the servers directly from your app. (kind of a pain for ios, not so much for android) or you can use a middle man such as:
FCM
Onesignal: https://onesignal.com/
Amazon Simple Notification Service: https://aws.amazon.com/sns/
or a bunch of others: http://www.businessofapps.com/guide/push-notifications/
I'm not familiar with signalR per se... but I'm very familiar with push notification. You can do everything you need with http api calls from signalR, but the certification requirements for the GCM and APNS servers are difficult to keep up on the app itself. (hence so many businesses that will do it for you.)
Although, I guess one thing I'm a little confused about exactly who you are pushing to... a web service? a phone? (I'm assuming a phone since you mentioned FCM)
Edit after first comment:
So, the answer (as I understand your question) is that you cannot go from signalR to a mobile device directly without using something like FCM (which I recommend) or Onesignal.
For Why... Let's start with a diagram:
You'll notice the bidirectional flow from the cloud marked APNS, GCM and FCM between the device. That means that only way to get to the phone via push notification is via APNS, and FCM, which you'll have to do through a push notification service.... such as FCM
Before any confusion sets in, let me point out some important point:
1. FCM and GCM are pretty much synonymous. FCM is the updated version of GCM that added some functionality. more info here
FCM is both a push notification service and the messaging service. That is to say that FCM provides both the services of the gray box and the gray cloud below. As far as I know, there is nothing similar in the ios world that does both. FCM allows you to pass along messages to both android and ios phones (via FCM and APNS)
So, you don't HAVE to go through FCM to do push notifications, but even if you picked OneSignal, they will still communicate with FCM to actually send out the push notification to the phones themselves.
You're doing the right thing by starting in the android world. Push notification is significantly easier there than in ios. (The difficulty lies in the certification process which is easy after you get to know it... but it was tough for me to understand at first)
In short, this is what I would recommend:
1. use ionic native push to communicate with FCM as a push notification service (the gray box)
2. setup FCM so that it can communicate with the APNS servers as well when the time comes.
for ionic native, I'd use their github site for documentation (I'm sure you've already been there) https://github.com/phonegap/phonegap-plugin-push
For setting up FCM, I'd recommend the documentation at the firebase website: https://firebase.google.com/docs/cloud-messaging/
Note: When using firebase products in ionic... choose "web" for all documentations. For example, despite the fact that you're planning on using ios and android phones, you'd pick "get started for web" at this link:
https://firebase.google.com/docs/

Background task on iOS

I plan to create a business app that runs on iOS and communicates with a webservice. The app is meant to be an online app, but when there is no internet connection, the user should still be able to register a notification locally and the app should send the notification automatically (without further user intervention) as soon as there is an internet connection again. This should also work when the user closes the app while he has no internet connection.
Is it possible to do this on iOS? (I know it works on Android with a service)
Does this need a special permission ?
Thanks
Check out this developer guide section, specifically the part about local notifications in iOS and Android.
Notice that services can work in native code but the local notifications are portable.

How do I set up an App Engine backend for a Chrome Extension?

I would like to be able to send a small push message from a Python Google App Engine server to a Chrome Extension. From searching the web, my best bet seems to be Google Cloud Messaging. (https://developer.chrome.com/apps/cloudMessaging)
However, the documentation for the Chrome extension side of GCM (as opposed to the Android side of GCM) is very poor. I cannot figure out what Python code to include in my App Engine server in order to communicate with the Chrome Extension.
The only info I can find is on the page linked to above, which has the following description of sending messages from a server to an extension:
Your app or extension client should register a handler to receive the gcm.onMessage event.
When your server sends a message to the user, it specifies all of the registration IDs that are related to that user and passes the message to the GCM service.
GCM servers route the message to all instances of Chrome running apps or extensions with one of the registration IDs.
When the message arrives on the client, Chrome starts the app or extension, if it is not already running, and calls the registered handler to process the message.
The documentation makes no mention of how exactly the server can pass the message to the GCM service.
I'm hoping someone out there has figured out how to send push messages from an App Engine server to a Chrome Extension.
Thank you for your time!
It's not the "Chrome extensions side", that's your conceptual problem. You're looking at the wrong documentation.
You are looking to implement a GCM Server, and the documentation is here.
You can also search for sample code, for instance this python GAE server.

Cross Platform Mobile Push Notifications

I know this isn't directly programming related, but couldn't find another StackExchange site to post this on. I'm using a minimally customizable template to create a few dozen mobile apps (under one publisher) using PhoneGap, and need to push notification messages to all users across the following platforms:
Android
iOS
Windows Phone
Blackberry OS 7+
We have a custom backend powered by ASP.NET MVC that needs to send notifications to mobile app users based on various events that are raised - such as when a certain date is reached send a certain message, or for announcements, as well as to send notifications about special offers.
I'm unsure if a full-blown push notification service like PushWhoosh or PubNub subscriptions are worth investing in or if we should rather opt for each platform's own service such as Apple's APNS and Android's GCM (not too sure what Blackberry services are available for push messaging to BB OS 7+).
I would really appreciate if someone could shed a little light on this matter and will tremendously help my decision making process.
Many thanks!
After finding a similar thread here on SO (Custom Apple Push Notification Server vs Urban Airship and likings), I've decided that it would be best to instead leverage each platform's native push service:
Apple Push Notification Service (APNS): here
Google Cloud Messaging (GCM): here
Microsoft Push Notification Service (MPNS): here and here
BlackBerry Push Access Protocol (PAP): here and here
Alternatively, use the open source PushSharp Library.
Hope this helps someone!
I'd suggest you try out those at QuickBlox (it's free of charge).
Here's the guide for iOS: http://quickblox.com/developers/SimpleSample-messages_users-ios
And the Android one: http://quickblox.com/developers/SimpleSample-messages_users-android
Not sure about Windows Phone and Blackberry though.
IBM MobileFirst supports
APNS / Push notifications in native iOS applications
GCM / Push notifications in native Android applications
MPNS / Push notifications in native Windows Phone applications
Push notifications in hybrid applications

Resources