简体   繁体   English

当应用未运行时,不会在iOS上触发`on('notification')`

[英]`on('notification')` is not triggered on iOS when app is not running

I'm using the phonegap-plugin-push on my ionic3 app and I've been facing this issue with the iOS platform (android is ok). 我在ionic3应用程序上使用了phonegap-plugin-push ,并且在iOS平台上一直遇到此问题(android可以)。 When the app is in background/foreground everything works as expected. 当应用程序在后台/前景运行时,一切正常。 When the app is not running however, I get the message on the notification tray but neither tapping the notification or the app icon triggers the on('notification') event, it simply runs and ignore the incoming notification. 但是,当应用程序未运行时,我会在通知托盘上收到消息,但是无论点击通知还是应用程序图标都不会触发on('notification')事件,它只会运行并忽略传入的通知。

I'm using the { ... content-available: 1} in the aps json message as suggested by the docs, but it doesn't seem to have any effect (though, it does have effect on Android), the ionic app itself never gets the message even though the device received it and displayed it on the tray. 我在docs所建议的aps json消息中使用了{ ... content-available: 1} ,但似乎没有任何效果(尽管它确实对Android起作用),离子应用程序即使设备收到了消息并将其显示在托盘上,它本身也从未收到消息。

Bellow, I show my configurations and a sample message sent to the push services. 在下面,我展示了我的配置和发送到推送服务的示例消息。 If anyone have any idea on how to sort this out will be appreciated, I've tested on ios 8.x and ios 11.x, both have presented the same behavior. 如果有人对如何解决这个问题有任何想法,我将在ios 8.x和ios 11.x上进行测试,它们都表现出相同的行为。

const options: PushOptions = {
    android: {
        senderID: '*************',
        icon: 'ic_stat_ic_notification'
    },
    ios: {
        alert: 'true',
        badge: 'true',
        sound: 'true'
    },
    windows: {}
};

platform.ready().then(() => {
    push.on('registration').subscribe((data: EventResponse) => {
        // register data.registrationId
    });

    push.on('notification').subscribe((data: EventResponse) => {
        alert(data.message)
    });
});

Sample message: 样本消息:

{
    "aps": {
      "alert": "This is a Push",
      "badge": 1,
      "content-available": 1
    },
    "payload": {
      "type": "news"
    }
}

This is too long of a comment. 这个评论太长了。 It's more of an indirect answer. 这更多是间接答案。

1) or the app icon triggers the on('notification') event <-- that's expected. 1) 或应用程序图标触发预期的on('notification')事件 <-。 Imagine your app just received 10 notifications. 假设您的应用刚刚收到10条通知。 How should it know which notification you intended to open? 它应该如何知道您打算打开哪个通知?

2) neither tapping the notification <-- this should trigger something in your code. 2) 均未点击通知 <-这将触发代码中的某些内容。 Do you have didReceiveNotificationResponse implemented? 您是否已实施了didReceiveNotificationResponse Does that get called? 有电话吗? Or does your didFinishLaunching get launched with a remoteNotification key? 还是您的didFinishLaunching使用remoteNotification密钥启动了? How about your application(_:didReceiveRemoteNotification:fetchCompletionHandler:) does that get called? 调用您的application(_:didReceiveRemoteNotification:fetchCompletionHandler:)怎么样?

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

相关问题 应用程序在前台时未触发通知-iOS - Notification not triggered when app in foreground - iOS 处于“未运行”状态时在iOS应用中推送通知 - Push notification in iOS app when “Not running” state 当应用程序已经在iOS上运行时,是否推送本地通知之类的通知? - Push notification like local notification when the app is already running on iOS? 当应用未处于运行状态iOS时通过通知横幅打开应用 - Open app through notification banner when app is not running state iOS 应用在前台运行时收到 iOS 推送通知 - iOS push notification received when app is running in foreground 当应用程序在 iOS 中处于运行状态时检测推送通知选择 - Detect push notification selection when the app is at running state in iOS 在 iOS 上收到通知时确定应用程序是否在前台运行 - Determine if an app is running in the foreground when a notification is received on iOS 当应用运行时,iOS推送通知显示为UIAlert - iOS Push Notification Shows up as UIAlert when App is Running iOS在前台运行时如何更改推送通知标题? - iOS how to change push notification title when app is running in foreground? 当应用被杀死而不在IOS的后台运行时如何获取通知有效载荷 - How to get notification payload when app is killed not running in background in IOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM