后台问题中的 Apple 推送通知 [英] Apple Push Notification in Background Issue
问题描述
我使用 parse.com 作为我正在构建的测试应用程序的 APNs 提供程序.我已经确认推送通知正在工作,因为当应用程序处于前台时我能够成功接收警报.另外,我在 plist 中指定了 UIBackgroundModes
键的 remote-notification
值.
在我的应用程序中,我想在收到推送通知时将用户的当前位置数据发送回我的应用程序特定的 parse.com 数据库.我实际上并不关心通知负载本身,因为通知只是获取一小部分信息的一种方式.该应用程序不断在后台收集数据并将其存储在持久的 NSDictionary
中.
我已经将位置发送代码放在了 application:didReceiveRemoteNotification:
方法中.如果我的应用程序在收到通知时处于前台,则会调用该方法.如果我的应用在后台,则不会调用该方法.
- 我做错了什么吗?
- 当应用程序在后台并且用户没有与通知交互时,是否甚至可以在
application:didReceiveRemoteNotification:
中执行 API 请求?**
即使我使用 application:didReceiveRemoteNotification:fetchCompletionHandler:
,问题仍然存在.
注意:我的 NSDictionary 充满位置数据不是空的.此外,我没有尝试在后台进行任何 UI 操作 - 只是尝试执行 API 请求.
检查以下内容:
- 通知负载包括内容可用"
{"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":""}
这篇关于后台问题中的 Apple 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!