简体   繁体   English

在后台iOS中接收推送通知

[英]Receiving push notifications in background iOS

I'm working on an app that receives push notifications from Zenpush service. 我正在开发一个从Zenpush服务接收推送通知的应用程序。 I managed to set up both app and account on Zenpush to sent and receive notifications. 我设法在Zenpush上设置应用和帐户以发送和接收通知。

When the app is active (opened) and I receive notification - everything is OK. 当应用程序处于活动状态(已打开)并且我收到通知时 - 一切正常。 I handle this in application:didReceiveRemoteNotification: . 我在application:didReceiveRemoteNotification:处理这个application:didReceiveRemoteNotification: .

Also, I can handle notification when user taps on it when it arrives, or opens app from the notification center. 此外,我可以在用户到达时点击通知处理通知,或者从通知中心打开应用程序。

The issue is - I can't handle notifications if the app is in the background, or terminated. 问题是 - 如果应用程序在后台或终止,我无法处理通知。 I've been struggling with this for a week now. 我一直在努力解决这个问题一个星期了。 I have both Background fetch and Remote notifications enabled in Background modes . 我在后台模式下启用了背景提取远程通知 In Scheme I checked "Launch due to background fetch event". 在Scheme I中选中了“由于后台获取事件而启动”。 According to Apple documentation and what I've found on StackOverflow I'm using following method to handle notifications in the background: application:didReceiveRemoteNotification:fetchCompletionHandler: . 根据Apple文档和我在StackOverflow上发现的内容,我使用以下方法在后台处理通知: application:didReceiveRemoteNotification:fetchCompletionHandler: .

No matter what i send in notification, this method is not called. 无论我在通知中发送什么,都不会调用此方法。 I tried to determine this by making changes to some data, and trying to NSLog something. 我尝试通过更改某些数据并尝试NSLog来确定这一点。

https://devforums.apple.com/message/873265#873265 https://devforums.apple.com/message/873265#873265

I include "content-available": 1 in my notifications. 我在通知中包含“content-available”:1。

Is there something else I'm missing? 还有什么我想念的吗? Or maybe there is a way to get all notifications that was receiver while app was in background/terminated where the app becomes active? 或者也许有一种方法可以获得所有通知,当应用程序处于后台/终止应用程序变为活动时接收器?

Stil not being able to get app to call application:didReceiveRemoteNotification:fetchCompletionHandler: I decided to debug what exactly i receive from Zenpush. Stil无法让应用程序调用application:didReceiveRemoteNotification:fetchCompletionHandler:我决定调试我从Zenpush收到的确切内容。 Turns out, using their Custom Payload section to add content-available is not the right way to do it. 事实证明,使用他们的自定义有效负载部分来添加content-available内容并不是正确的方法。 This way content-available is added after asp object, not inside of it. 这样,在asp对象之后添加content-available ,而不是在asp对象之内。

I wrote to Zenpush support about it, if i get any info on how to send content-available inside asp i will edit this answer 我写了关于它的Zenpush支持,如果我得到任何关于如何发送content-availableasp里面我可以编辑这个答案

Update: 更新:

I got the response from Zenpush support. 我得到了Zenpush支持的回复。 This feature is tested now, and will be available soon. 此功能现已测试,即将推出。

Update 2: 更新2:

Zenpush added a checkbox for background services, and now it works just fine. Zenpush为后台服务添加了一个复选框,现在它的工作正常。 在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM