How does WhatsApp know if the user gets the push notification even if the app is runnng in the background and is not open? - iphone

I have already asked related question:
any option to know if apple app get the push notification?
And I got an answer that it is not possible to know if push notification comes to the iPhone when application is in the background and the user does not have it opened...
But I found something interesting:
I take 2 iPhones with WhatsApp. I open, in the first iPhone, WhatsApp and exit it (the WhatsApp is in the background now), then with the second iPhone, I send WhatsApp massage to the first iPhone.
When the push notification of WhatsApp reaches first iPhone I can see two "V" (symbols) near to the message (and I don't open the Push notification). After this I close the Internet & 3G in the first iPhone and again send WhatsApp message with the second iPhone to the first one. - and I can see only one "V" near to the massage (not read - not get push notification).
Now after re-enabling the Internet on the first iPhone and after I get the push notification I can see two "V" (again - I don't open the push notification).
How does it work? How does WhatsApp know whether the iPhone gets the push notification or not while the WhatsApp works in the background?

Let us call the iPhone with WhatsApp application closed - the receiver and the other iPhone you send messages with - the sender, and let us use generic term application instead of WhatsApp
The application at the sender is not able to learn that push notification has reached the receiver. It is by the nature of push notifications.
However, the sender is possible to send another - not a push notification, but prioprietary protocol - message to the application at the receiver which it (the receiver) is welcome to acknowledge to the sender in any application-specific way it wants.
So, I would guess (I don't know - I'm not affiliated with WhatsApp in anyway) that the double-v icon you get is when application message reaches the application at the receiver - and has nothing to do with push notification.

What you mean is just the basics of push-technology :
The whatsapp software runs in the background listening on a specific port
for incoming messages. It does this continuously.
BTW :
One V = message delivered from your mobile to the whatsapp server
Two V's = message pushed from whatsapp server to recipient mobile
Blue V's indicate message has been read

Whatsapp doesn't show if the person reads the message or not. It just informs when the message has been sent to the whatsapp servers(one V) and when it has been sent the person phone (2 V's). The double does not mean the message was read it just means that whatsapp connected to the phone and was able to pass on the message.

After receiving a push notification the receiver can download data from a URL that you include in the payload of your push notification. By requesting that URL the server knows that the receiver received the push notification and can pass this status on to your sender application.
Like so:
Add a specific URL in your push notification payload
Implement the application:didReceiveRemoteNotification:fetchCompletionHandler: method in your app delegate and in that method call the URL from the payload.
Implement a logic on your server that recognizes the URL call as a received notification
Let your sender application continuously get the current notification status from the server.

The above posters are all correct. Just to add one more thing. If Whatsapp has recently been closed, it is still running in the background and can still receive the message (hence the return receipt). However, after the app is left unused for a while (or other apps have higher priority) Whatsapp is terminated, then it will no longer receive incoming messages and will not return receipt.
Of course the observant person would notice a small lag between opening the app and the new messages being displayed which seems to suggest the messages are not downloaded in the background but only downloaded upon opening the app. So why does it return receipt while running in the background?

Related

How to send push notifications in swift 4 when something happens?

I am creating an app in Swift 4 and I want it to send a push notification when the wind is above a specific value. I already have the app created and when you open the app you can see the current wind (scraped from a website).
Is it possible to send a message when my phone is turned off and the app isn't running? and how to do that?
You need a server to send push notifications when your phone is turned off.

How Google's Gmail app on iPhone disable notifications?

My question can seems weird, but I just realize that when I receive a push for a new mail from Gmail app and I open Gmail on a web page, the notification disappear.
Can someone explain me how this is working ?
This is related to this question, though it's not an exact duplicate.
This can be implemented with Apple Push Notifications.
Your server has to maintain for each user a list of device tokens of all the devices belonging to that user (iPhones, iPads, etc...).
When the user reads the message on one platform (whether via a web browser or via a mobile application), you can execute some API call on your server to notify it that the user read the message.
Then your server can send a follow-up push notification to all the devices belonging to that user with "badge"=0 (and without the "alert" and "sound" fields), and the notification will be cleared from the lock screen and app icon.
One possibility is that they use notifications delivered in the background (they get delivered directly to the app rather than being shown to the user), then use local notifications. Local notifications can be cancelled.
So it would go like this:
remote notification "there's a new e-mail" delivered in the background
local notification "new email"
...
you connect to the website
remote notification "user has seen new e-mail" delivered in the background
cancel local notification
I've never actually tried to do this, but I suppose that would be the way it works. I'm not aware of any (documented) way to cancel a remote notification directly.

any option to know if apple app get the push notification?

I build xcode app that get push notification, the main problem is that the push notification is very critical for me.
so I want to check if the push notification is delivered to the device with the app installed, I understand that if the iphone dosn't have internet connecction / 3G the push notification is not getting to the device.
how can I check if the device get the notification or not?
how can I check if the APNS successful to deliver the push notification?
I want to send sms if the push notification is not deliver to the device so I think about the idea to get the notification event when it's open by the push notification, and to send request to my server so i can know if the push notification is successful deliver or not. the main problem is that the user need to open the app every time he get the notification and in the night it's a problem. so this option is not good for me.
I check the feedback server push notification but i don't find any info that I can get if the push notification is delivered or not
any idea??
With iOS7 you have a new method called
application:didReceiveRemoteNotification:fetchCompletionHandler:
which you probably could use for your task. From Apple's Docs:
Implement this method if your app supports the remote-notification background mode.
...
When a push notification arrives, the system displays the notification to the user and
launches the app in the background (if needed) so that it can call this method. Use this
method to download any data related to the push notification. When your method is done,
call the block in the handler parameter.
Unlike the application:didReceiveRemoteNotification: method, which is called only when
your app is running, the system calls this method regardless of the state of your app.
The short answer, you can't, since APNS is one way. However, since an app can execute arbitrary code upon receipt of a notification, you can use this to say, send an http request to your own server when the notification is recieved.
There are any number of reason why push notifications might not get delivered to your user, or might not be delivered in a timely manner. Apple does not provide any mechanism for you to query the status of a push notification that you have sent.
If your app is currently running on the user's device and the user is accepting notifications for your app, you can implement the following method in your app delegate. It would be called whenever a push notification is received and in this method you could send a request back to your server to indicate the message was received. However this will only work while the user is running your app.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
In general though, it sounds like you'e relying on push notifications for something you shouldn't. From Apple's Local and Push Notification Programming Guide:
Important Because delivery is not guaranteed, you should not depend on
the remote-notifications facility for delivering critical data to an
application via the payload. And never include sensitive data in the
payload. You should use it only to notify the user that new data is
available.
There is no way to find out whether the notification was delivered to the device or no. APNS is a one way service. If there is no internet connection on the device then the APNS server will hold the last notification for some period of time which is no specified by Apple. If a new notification is sent to APNS for delivery then the old notification data is lost and replaced by the new data if its undelivered. If the notification is delivered then also the old notification data is deleted on the APNS server.
Please go through the following link : Apple Push Notification
Hope this helps you...........
If you are using JAVAPNS to send the APNS notification, you can use the below:
List<PushedNotification> notifications =
Push.combined("alert", badge, "default", "cert.p12", "certpassword", true, deviceToken);
for (PushedNotification notification : notifications) {
if (notification.isSuccessful()) {
//Push is successful. Do your thing...
}
else {
//Push is not successful. Do your thing...
}
}

Is is possible for an application to handle the response from a push notification?

Is it possible to get the user's response from a push notification and create a notification reply? i.e. if a user clicks the view button and views the app, can we take that action and let the sender of the notification know that the receiver has viewed / opened the app?
Short answer, Yes.
When the application starts due to a user electing to from a notification (local or remote) the application is started in a special way so that the application can process the notification. At this point it can do whatever you want, like send a message back to your service.
See Handling Local and Remote Notifications for details.

Reading the APNS Payload using the Client

I was wondering if it is possible for the app on the client to be able to read the data in the payload when an APNS notification is sent?
For example, if the APNS notification said "Hello world!", and the user clicked 'View' to go to the app, would there be a way for the app to see that the APNS notification said "Hello world!".
Thanks.
APNS notifications are tied to a specific token which is associated with a specific app on a single phone. When the notification arrives, iPhone OS shows the user the alert, plays the sound (if specified), and sets the application badge (if any).
If the app is running and the screen isn't asleep the app is run and the payload JSON packet is handed over. If the app is running and the screen is dark, the user is shown the alert with a single button to unlock the screen then the app is handed the payload. If the app is NOT running the user is given a View/Cancel choice. If they tap View, the app is run and the payload JSON is handed over.
As you can see, in all these cases the JSON packet containing the notification alert, sound, badge, and any other extra bits you send is handed over to the application. The docs show you how to retrieve the JSON packet. It's up to you what to do with it.
If you're thinking of an app seeing the payload headed for another app, then the answer is no. Notifications are tied to specific apps signatures.