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

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.

Related

How to remove a specific push notification from notifications center Swift

my App is an app like Uber app, I sent a task to all my drivers this will be by a push notification.
But when a driver accepts the task first I need to remove the sent push notifications from all drivers devices so it won't be show in the notification center.
I search a lot about this issue, but no answers!
anyone try to delete a specific push notification from the notification center after sent it?
thanks.
You need to send a silent push-notification that triggers a local notification with a specific identifier.
This identifier should be send inside the silent push notification, that also should carry all information the driver should see in the local notification.
you need two types of push-notifications: show, hide.
got the point?

Push notification data when app is not running?

When the app is not running and user receives, say 5 push notifications, are those push notifications saved somewhere? Or is that data gone? I need to access all 5 push notifications when the app runs the next time.
To clarify, I already understand that you can access the push notification that caused the app to run. What I'm asking is to get all push notifications since the app got terminated.
The APNS service will only retain the most recent pushed message to a device - assuming there is still at least one other app installed AND the user allows push notifications for it, then this one stored message will be delivered the next time the user has an Internet connection.
For better information on the quality of service that Apple has implemented for the APNS service, see my other answer here:
Clarification on Apple APNS

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

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?

How to tell user about what are recently received push notifications

Is it possible to tell user what were about recently received push notifications ? I mean, if user clicks cancel when push was received, there is a badge on the icon of my application, but that's all. I think this is not user friendly and such notifications have no sense. When user opens an application, he knows that there is something new in it, but don't know exactly what. Do I need to make some requests to my web server to have information about my last pushes or I'm missing something and there is another way ?
From the implementations of push notifications I've worked with so far, you'll need to make a call to your server when the app actually starts up in order for the app to know what the new information is. I don't believe there's any way to store received push notifications unless your app is opened and handling them in the app delegate. Otherwise if push notification is closed it's discarded.
In all the apps I've worked with that utilized push notifications there was a place in the app where all the recent notifications were displayed after a call to the server was made to get the whole list.

iPhone Push Notification Reliablity

How reliable do you find push notification on the iPhone to be? Does it improve when moving from the sandbox to production server?
I am testing (with the sandbox of course) and have found that notifications are often delayed or not received at all. I am not talking about sending multiple messages and only the last one arriving, as the documentation indicates, but any notification never showing up.
Also, I noticed that if I send a notification with an alert, and then send one with just a badge number, that the second notification will close the alert even after it's already opened. Does this happen between apps as well? For instance, if I send an alert for my app, and then the Facebook app sends a badge, will the Facebook badge close my alert window?
I have no development experience with iPhone apps, but I do know that if you have an unofficial unlocked phone (by using pwnage tool/blackrain etc) then the PUSH notifications might NEVER go through. In fact, it does go through, but to another user's iPhone.
This is because when an iPhone is unofficially network unlocked, it uses the Unique ID of some random individual's iPhone, which causes Push notifications to arrive on either phone (and yes, sometimes also on the unlocked phone it was intended for, but usually not)
Not sure if this is the case with you though, but AFAIK the service is pretty reliable if you follow Apple's rules. :)
The push notification seams better on production. You can always test it using ad-hoc distrbution which uses the production chanel to send the notifications.
I can confirm that production push notifications using
Production Push Notification Certificate
Adhoc Distribution Mobile Provisioning
TestFlight deployment
Production APNS server
works well, no need to publish your app to test production notifications
Production push notifications are not always received. If notifications are machine gunned 1 second apart the first one is received and the rest are not sent, thats my experience.
Where as on a windows phone, they are all received using the windows notification service.