我在didReceiveIncomingPushWithPayload方法中遇到问题,因为当应用程序被终止/终止时它不会触发。但是当应用程序在后台运行时,效果很好。
调查后,我发现有人建议使用新版本,因为该版本已被弃用
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
DispatchQueue.main.async(execute: {() -> Void in
completion()
})
}
效果很好,但是此方法仅适用于iOS 11+,因此不适用于iOS9。有什么建议吗?
答案 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()
}
希望有帮助。