首页 文章

从自定义服务发送邮件时未调用didReceiveRemoteNotification

提问于
浏览
0

我有一个成功发送通知的自定义通知服务,但是当用户点击通知时,永远不会调用didReceiveRemoteNotification . 该应用程序将打开到最后一个状态,我正在尝试深入链接到应用程序中的特定场景 .

在我的didFinishLaunchingWithOptions中,我通过调用此函数来注册通知类型“

func registerForPushNotifications(application:UIApplication){let notificationSettings = UIUserNotificationSettings(types:[ . badge,.sound,.alert],categories:nil)UIApplication.shared.registerUserNotificationSettings(notificationSettings)}

我正在使用后端服务注册我的设备,并调用didRegisterForRemoteNotificationsWithDeviceToken函数

接下来我有我的didregister功能

func application(_ application:UIApplication,didRegister notificationSettings:UIUserNotificationSettings){UIApplication.shared.registerForRemoteNotifications()}

最后,我有一个didReceiveRemoteNotification,我希望在点击通知时调用它 .

func application(_ application:UIApplication,didReceiveRemoteNotification userInfo:[AnyHashable:Any]){}

发布到我的后端服务的xml相当直接,似乎按预期工作:{“audience”:{“ios_channel”:“e06b9r8r-ffce-4fa6-92ec-123456789”},“notification”:{ “ios”:{“alert”:“测试声音发送”,“ Headers ”:“测试警报”,“声音”:“默认”}},“device_types”:[“ios”]}

如果有人输入为什么没有调用didReceiveRemoteNotification func将非常感激 .

2 回答

  • 0

    didReceiveRemoteNotification 仅在您的应用程序打开时触发 . 要响应用户点击通知,您需要检查 didFinishLaunchinglaunchOptions 参数中的 UIApplicationLaunchOptionsRemoteNotificationKey 值 .

  • 0
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
      if let userInfo = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] {
                NSLog("[RemoteNotification] applicationState: \(applicationStateString) didFinishLaunchingWithOptions for iOS9: \(userInfo)")
                //TODO: Handle background notification
    
    
            }
            return true
        }
    

相关问题