怎么自定义 node-webkit 通知的 标题 和 图标

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎么自定义 node-webkit 通知的 标题 和 图标相关的知识,希望对你有一定的参考价值。

参考技术A 要打包一个双击就可以直接运行的node-webkit应用,需要有:自己做的项目文件、package.json的配置文件,还有下载下来的node-webkit。 一、打包一个可以运行 .nw文件 1、在要打包的项目的主页面同一级目录里建一个package.json的文件,它是用来配

自定义操作按钮未显示远程通知

【中文标题】自定义操作按钮未显示远程通知【英文标题】:Custom action buttons didn't show for remote notification 【发布时间】:2019-08-10 06:53:05 【问题描述】:

我正在关注this 生成通知的教程。如图所示,自定义按钮对于本地通知是可见的。但是当我尝试对遥控器进行同样的操作时,它没有用。

这是我为通知设置类别的代码:

func registerActions() 
    var notificationActionOk :UIMutableUserNotificationAction = UIMutableUserNotificationAction()
    notificationActionOk.identifier = "ACCEPT_IDENTIFIER"
    notificationActionOk.title = "Ok"
    notificationActionOk.isDestructive = false
    notificationActionOk.isAuthenticationRequired = false
    notificationActionOk.activationMode = UIUserNotificationActivationMode.background

    var notificationActionCancel :UIMutableUserNotificationAction = UIMutableUserNotificationAction()
    notificationActionCancel.identifier = "NOT_NOW_IDENTIFIER"
    notificationActionCancel.title = "Not Now"
    notificationActionCancel.isDestructive = true
    notificationActionCancel.isAuthenticationRequired = false
    notificationActionCancel.activationMode = UIUserNotificationActivationMode.background

    var notificationCategory:UIMutableUserNotificationCategory = UIMutableUserNotificationCategory()
    notificationCategory.identifier = "INVITE_CATEGORY"
    notificationCategory .setActions([notificationActionOk,notificationActionCancel], for: UIUserNotificationActionContext.default)
    notificationCategory .setActions([notificationActionOk,notificationActionCancel], for: UIUserNotificationActionContext.minimal)

    UIApplication.shared.registerUserNotificationSettings(UIUserNotificationSettings(types: UIUserNotificationType(rawValue: UIUserNotificationType.sound.rawValue | UIUserNotificationType.alert.rawValue |
        UIUserNotificationType.badge.rawValue), categories: NSSet(array:[notificationCategory]) as! Set<UIUserNotificationCategory>
    ))

//        fireLocalNotification()

这是我添加的相同类别的有效负载。

"to": "cMGOnedo5M4:APA91bEQgj1Dt5IWsqgdq2QQmGBv-zAxH4qsWRApkeAA5fvxCZPKQACkok_sWC3v2mwT3SnFrK_08qgmy9bcac0PxSJkSWhJMKbWPnBzHWBnv2yKPY-FjSynLgGYTiK7bl5LejcaVQbr", 
"notification" : 
    "body" : "   ","title": "You have received a message from jia ron","badge": "1" ,
"data" : 
    "OriginalFileName":null,"FilePath":"https:Chat//3458/","ChatID":3826,"From":3458,"To":3440,"Message":null,"SendDate":"2019-07-03T00:00:00","ServerDate":"","ModifyDate":"","SendType":"TEXT","IsDelete":false,"IsRead":false,"SendByMe":0,"Type":"OfflineChat","message":null,"UserID":"3458","DisplayName":"jia ron","MessageType":"TEXT","IsGroup":0,"GroupID":0,"FileName":null,"UnreadMessage":3,
"aps" :
  "category" : "INVITE_CATEGORY"

这是触发本地通知的代码。

func fireLocalNotification() 
    var localNotification:UILocalNotification = UILocalNotification()
    localNotification.alertAction = "Testing notifications on iOS8"
    localNotification.alertBody = "Woww it works!!"
    localNotification.fireDate = NSDate(timeIntervalSinceNow: 30) as Date
    localNotification.category = "INVITE_CATEGORY";
    UIApplication.shared.scheduleLocalNotification(localNotification)

从本地通知中,我有两个拉动按钮。

但没有出现在远程推送上。

【问题讨论】:

【参考方案1】:

请按以下方式更改您的通知负载 JSON

"to": "d8xNDuQIua8:APA91bF15SABFUBNDEYb2JJ4_LGlDZ94G3TMryWIo0SFKE1xyr9VThS6Ce-NofxXtIAw_yMr5jFwUcEzk-JxqpqkJ5OiOYzftcukyef1VcX4a7I25BagAytp48GVt1VJueY49K2cAKcA",
     "notification": 
         "text": "YOUR_PUSH_TEXT",
         "click_action":"INVITE_CATEGORY"
     

【讨论】:

以上是关于怎么自定义 node-webkit 通知的 标题 和 图标的主要内容,如果未能解决你的问题,请参考以下文章

node-webkit windows下怎么打包

Node-Webkit:如何在本地文件系统中创建文件?

node-webkit打包的exe文件的图标怎么更换

在 node-webkit 中获取当前应用程序的路径

带有自定义协议的 Javascript SDK API 域?

node-webkit打包的exe文件的图标怎么更换