简体   繁体   English

在Swift上推送通知

[英]Push notifications on Swift

I have a really big problem with Firebase Notifications; 我的Firebase Notifications有一个很大的问题; my problem is that i can receive notification in background mode and foreground mode, but if I terminate it(kill it from the ram) I can't receive anything. 我的问题是我可以在后台模式和前台模式下接收通知,但是如果我终止它(从ram杀死它),我什么也收不到。

I found that if I comment this function 我发现如果我评论此功能

func application(_ application: UIApplication,
                 didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Messaging.messaging().apnsToken = deviceToken
}

I can receive a notification when i reopen the application after it's terminated, but i can't get a notification in background like before. 终止后重新打开该应用程序时,我会收到通知,但无法像以前一样在后台收到通知。

There's any way to solve it, because my application should receive notification everytime: background, foreground and when application is reopened from a terminated state 有什么方法可以解决它,因为我的应用程序应该每次都收到通知:后台,前台以及从终止状态重新打开应用程序的时间

The following is an example of my notification's JSON: 以下是我的通知的JSON的示例:

{
"content_available": true,
"priority": "high",
"data": {
    "priority": "SILENT",
    "target": "contact",
    "msgBody": "",
    "msgTitle": ""
},
"to": "firebase_TOKEN"

} }

I also want to say that this notification should be silent 我也想说这个通知应该保持沉默

您必须要求在通知中添加"Content-available" : "1",以在应用程序终止时获得推送通知。

When app is killed notification will be handled from operating system so it needs some specific key to display notification. 当应用被终止时,将从操作系统处理通知,因此它需要一些特定的键才能显示通知。

Like consider the below example: 像下面的例子:

{

"content_available": true, 
  "notification": {
    "title":  "has sent you a message", 
    "sound": "default", 
    "body": "Hi", 
    "badge": 6

  }, 
  "to": "firebase_TOKEN", 
  "priority": "high"
}

Here you need to replace "data" with "notification" and you also need a "title" instead of "msgTitle" and "msgBody" will be replaced with "body" . 在这里,您需要将"data"替换为"notification" ,还需要一个"title"而不是"msgTitle"并且"msgBody"将替换为"body"

Looks like your's is a android payload which won't work with iOS. 看来您的是Android负载,无法在iOS上使用。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM