Would someone happen to know a small code sniplet to get and compare the users location before they see a push message inside the appDelegate class?
If the app isn't running, then you can't 'get in the way' the message will be displayed to the user. And where I say running I mean in the foreground and with the screen on.
If the app is running, then you can embed arbitrary information (such as a relevant location) with the push notification payload. When this is delivered to your app's delegate, you can check for their location as you normally would, and if the user is where you'd like them to be you can pop up a message to them.
It seems like a lot of hard work for people that are actually using the app at the time that the notification is delivered though. What will you do about all the users who aren't running the app and get the push notification popup without the check?
Related
My app is receiving APNs sent from server to Apple backend. Naturally a user may not open the app once a notification arrives to user's device. In meantime my server may push more notifications. They all contain some user data that is important when a notification is processed. So how to deal with it? iOS won't bundle and give me a batch, will it?
Here are ways how I am going to tackle it, none of which is simple.
Server keeps track of not seen data and upon arriving a new request always sends a batch of all new notifications, reflecting the count as badge count.
Client is opened by taping on notification popup. In this case it has all needed data in didReceiveRemoteNotification.
OR
Client ignores notification popup and opens app (possibly later) by tapping on app icon. In this case didReceiveRemoteNotification is not called and thus app has to fetch all needed data from server.
OR
Server never sends any user data and client always checks for new stuff every time it starts or fetches data in didReceiveRemoteNotification.
Anything else? Something simpler I am missing?
Number 4 is the right approach. There is no guarantee that any of your app code will run when an APN is received, except on iOS7. So when your app starts, it has to check with your servers for any new information that it should display.
It's simplest to code this to alway ask your servers for the latest information to display, rather than rely on the information in the APN. Use the information in the APN only to determine which new information to navigate to, so that the app displays whatever the user tapped on.
This has changed with iOS7, where you can use the remote-notification background mode to be launched whenever a push message arrives. See https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification:fetchCompletionHandler:
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.
I have implemented all recommended methods in AppDelegate to get working Remote Notifications service.
I can accept them while running, while launching and while turned off.
But there is an issue, since I can't work with many received notifications while in background. I can work only with latest notification.
What is recommended manual to do that? How can I got all notifications received while in background? Is it only solvable via manual call to my service provider (sender of apns data)?
With all the projects I've worked on there hasn't been a way to locally store this information if the push notification is dismissed. In all those cases we used a small file on the server that the app would connect to and pull when it became active again. There was also some place in the app where the user could see all their notifications which, again, were stored on the server for quick retrieval.
With the way I understand push notifications to be setup, if the notification is dismissed the system discards it. It'll perform anything it's supposed to do (such as update the badge number and play the correct sound) but any additional information specific to that notification is lost.
Not sure if this helps, but if you just want to know how many notifications you have missed while you were in background. You can create a variable which contains notification number and store this in the app every time you handle notification. When you come out of background and receive a new notification you can subtract the new number with the stored number to find out the number of missed notifications. I don't think there is a way where iOS can give you complete data associated with all the notification device have received while the app was in background.
The best solution is to keep a list of sent notifications with all relevant data on your server, so the app can access that data when it launches. Sending multiple notifications with data that is not stored on the server can be risky, because the application only receives the notification when the user opens the app from that notification, so if they tap on one notification, the app will only every receive that one.
If you have them all in a list on your server, the app can simply go and pull that list down, and process it, making sure no data is lost.
I am running into a problem here. I am able to receive, capture and save an APNS message just fine if I do it while my app is running or if I click "View" when it comes in if the app is closed.
The problem I am running into is.. If the app is NOT running and I receive a APNS message and chose to look at it later by selecting "Close"... the next time I open the app, the app is not opening "with options". Therefor, the APNS message is lost. The same thing happens if the screen lock comes on before "viewing" the APNS message.
How do I handle this?
Thanks in advance!
Don’t assume that push notifications will make it to your app—their delivery isn’t guaranteed, even if the user doesn’t “close” the alert a notification brings up. Your server should have the authoritative state of whatever notifications your app needs to display when it launches, and the app should check that state regardless of whether it’s launched from a notification or not; one reason for this is that if your app receives multiple notifications while in the background, only one of those notifications will get delivered to the app when the user chooses to view it.
I am implementing a push notification functionality for my app and everything is running smoothly except for one case.
The situation is this:
When the app is off (not running in background either) and the user receives a push notification. The user hits "Close" and then later on decides to go to the app. I would like my app delegate to know the push notification that was received earlier however, I don't know how to check that. I know that I can have a function call in my didLaunch... but that works when the user decides to hit the "View" button instead of "Close".
Any hints?
Thanks!
Really, the answer is don't bother. You can never guarantee that the alert was received, so unfortunately you'll run into problems later if you rely on this. apns doesn't guarantee a device will receive a payload.