Apple Push Notification in Background Issue
Check the following:
- Notification payload includes "content-available"
{"alert":"", "badge":"0", "content-available":"1", "sound":""}
Comments
-
ArtSabintsev almost 2 years
I'm using parse.com as my APNs provider for a test app I'm building. I've confirmed that push notifications are working as I have been able to successfully receive alerts when the app is in the foreground. Also, I have the
remote-notification
value for theUIBackgroundModes
key specified in my plist.In my app, I'm wanting to send a user's current location data back to my app-specific parse.com database when a push notification is received. I don't actually care about the notification payload itself, as the notification is just a means to getting a small piece of info. The app is constantly collecting data in the background and storing it in a persistent
NSDictionary
.I've put the location sending code in the
application:didReceiveRemoteNotification:
method. If my app is in the foreground when I receive a notification, the method gets called. If my app is in the background, the method isn't called.- Am I doing something wrong?
- Is it even possible to execute an API request in
application:didReceiveRemoteNotification:
when the app is in the background and the user hasn't interacted with the notification?**
EDIT: The problem persists even when I use
application:didReceiveRemoteNotification:fetchCompletionHandler:
.Note: My NSDictionary full of location data isn't empty. Also, I am not attempting to do any UI manipulation in the background - just trying to perform an API request.
-
ArtSabintsev over 10 yearsI guess I understood
not running
as totally shut down, notinactive
orbackground
mode. I'll try it out momentarily and mark your answer correct if I get it working. -
ArtSabintsev over 10 yearsIt's still not working. I am now attempting to send the location data from both
application:didFinishLaunchingWithOptions:
andapplication:didReceiveRemoteNotification:
. If the application is in the background (e.g., I pushed the home button), no data is sent, UNLESS I interact with the notification. If I interact with the notification by clicking on it, theapplication:didReceiveRemoteNotification:
method is entered. What am I doing wrong? Do I fundamentally misunderstand how background notifications should work? -
ArtSabintsev over 10 yearsI think my app is actually in the
suspended
state, and not thebackground
state. I think that's what may be causing the issue. -
RyanR over 10 yearsDid you set the remote-notification flag in the info.plist?
-
ArtSabintsev over 10 yearsYes, I did. I also have been using the new
application:didReceiveRemoteNotification:fetchCompletionHandler:
method, which supersedes the other delegate methodapplication:didReceiveRemoteNotification:
. Still, no dice. -
ArtSabintsev over 10 yearsThat worked! I had the
content-available
flag turned on in the AppDelegate, but wasn't pushing that flag in my JSON APNs. Thanks, Alex! That fixes the problem. -
ArtSabintsev over 10 yearsHah, odd. It worked only one time. Will look into it and get back to you
-
ArtSabintsev over 10 yearsNevermind, got it working! It was just a delay in receiving the data from parse.
-
Simon almost 9 yearsAccording to the iOS developer library "content-available" is for silent push notifications: "The aps dictionary can also contain the content-available property. The content-available property with a value of 1 lets the remote notification act as a “silent” notification. When a silent notification arrives, iOS wakes up your app in the background so that you can get new data from your server or do background information processing. Users aren’t told about the new or changed information that results from a silent notification, but they can find out about it the next time they open your app."