didReceiveIncomingPushWithPayload当应用被杀死时不起作用

时间:2018-08-28 05:38:49

标签: ios iphone apple-push-notifications callkit

我在didReceiveIncomingPushWithPayload方法中遇到问题,因为当应用程序被终止/终止时它不会触发。但是当应用程序在后台运行时,效果很好。

调查后,我发现有人建议使用新版本,因为该版本已被弃用

func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {

DispatchQueue.main.async(execute: {() -> Void in completion() }) }

效果很好,但是此方法仅适用于iOS 11+,因此不适用于iOS9。有什么建议吗?

1 个答案:

答案 0 :(得分:1)

我这样得到,它可以在iOS 10和11上运行。

 //available(iOS, introduced: 8.0, deprecated: 11.0)
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
    pushRegistry(registry, didReceiveIncomingPushWith: payload, for: type) {
        // no-op
    }
}

//available(iOS 11.0, *)
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {

    //your code
    completion()
}

希望有帮助。