Apple Push Notification 设置远程通知方法覆盖其他方法 [英] Apple Push Notification setting up Remote Notifications method overrides other methods

查看:24
本文介绍了Apple Push Notification 设置远程通知方法覆盖其他方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用方法

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject], fetchCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void)

现在每次应用收到 Apple 推送通知时它都会正确处理它.

and it processes it correctly now every time the app receives an Apple Push Notification.

但我的问题是这个方法现在在所有实例中都被调用.

But my issue is that this method is being called in all instances now.

didFinishLaunchingWithOptions 似乎不再被调用?或者 launchOptions 是空的?

didFinishLaunchingWithOptions does not seem to be called anymore? Or the launchOptions is coming up empty?

基本上,我使用 didReceiveRemoteNotification 作为处理所有传入通知的方法,这是我的预期目的,但是当我单击通知本身时,它会触发 didReceiveRemoteNotification再次.因此处理了两次通知,这是我不想要的.

Basically I used the didReceiveRemoteNotification as a catch all to process any incoming notifications which is my intended purpose, but then when I click the notification itself, it fires the didReceiveRemoteNotification again. Thus processing the notification twice, which I do not want.

这就是我希望我的应用程序处理通知的方式:

So this is how I want my app to handle notifications:

  • 任何时候收到通知,都想在后台自动处理通知
  • 当用户点击来自外部应用的通知时,运行与 didReceiveRemoteNotification 不同的方法
  • 当用户在应用程序内时,运行与另一个不同的方法

推荐答案

Apple 不允许你想要的.推送通知的工作方式如下

Apple does not allow what you want. Push notifications work in the following way

1) 当应用程序没有运行,并且用户点击通知时,应用程序被启动并且通知的有效负载被加载到函数 didFinishLaunchingWithOptions 中.

1) When the application is not running, and the user clicks a notification, the application is launched and the payload of the notification is loaded in the function didFinishLaunchingWithOptions.

2) 当应用程序在后台运行并且用户点击通知时,应用程序变为活动状态并调用函数didReceiveRemoteNotification.现在这个函数包含通知的负载.

2) When the application is running in background, and the user clicks a notification, the application becomes active and the function didReceiveRemoteNotification is called. Now this function contains the payload of the notification.

3) 当应用程序运行并调用推送通知时,函数 didReceiveRemoteNotification 被调用,该函数包含通知的负载.

3) When the application is running and a push notification is called, the function didReceiveRemoteNotification is called and this function contains the payload of the notification.

4) 当应用程序在后台运行或处于非活动状态并收到通知时,在用户点击通知之前无法对通知进行任何操作

4) When the app is running in background or inactive and notification is received, nothing can be done with the notifications until the user clicks the notification

这篇关于Apple Push Notification 设置远程通知方法覆盖其他方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆