且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

后台问题中的 Apple 推送通知

更新时间:2023-12-03 16:57:28

检查以下内容:

  • 通知负载包括内容可用"
{"alert":"","徽章":"0","内容可用":"1",声音":""}

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 the UIBackgroundModes 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.

Check the following:

  • Notification payload includes "content-available"
{"alert":"",
"badge":"0",
"content-available":"1",
"sound":""}