2016-11-16 216 views
0

我想发送一个图像内的通知。但在对象属性中无法添加图像。科尔多瓦本地通知插件

这里是插件:https://github.com/katzer/cordova-plugin-local-notifications/wiki/05.-Update

荫想,如果我可以修改通知对象在本地通知发送图像。

+0

http://stackoverflow.com/questions/28718872/push-notifications-with-big-images-using-cordova-push-plugin请访问它 –

+0

与此问题无关。我正在使用本地通知。 – Sreinieren

+0

使用图标选项,您可以轻松地设置通知中的图像。 –

回答

0

您可以将图像转换为base64编码图像,然后将编码图像添加到通知对象。

下面是一个例子:

var notificationObj = { 
    title: "My title goes here", 
    description: "My description goes here", 
    img:"image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABg....AElFTkSuQmCC" //this is the base64 encoded image 
} 

//Schedule the notification code goes here 

然后你就可以访问base64编码图像时通报火灾

cordova.plugins.notification.local.on("click", function (notification) { 
    //The property notification.data.img now contains the base64 encoded image and 
    // you can use it directly as a source for <img> tag. Example: 

    document.getElementById("myImage").src= notification.data.img ; 
}); 
+0

你会怎么做?我使用这个在线转换器:https://www.base64-image.de/ 但我不知道什么包括在通知的messgae?该html还是什么? – Sreinieren

+0

我试着用这个输出:http://www.dailycoding.com/Utils/Converter/ImageToBase64.aspx。但它只显示输出为字符串 – Sreinieren

+0

这就是要点,您将图像转换为base64编码的字符串,以便您可以将其存储在通知对象中。 然后,当用户单击通知时,它会以通知对象的字符串形式检索,然后您可以随意使用它。 – Dola

-1

计划通知

这也是可以通过一次安排多个本地通知分配散列数组。

cordova.plugins.notification.local.schedule({ 
    title: "New Message", 
    message: "Hi, are you ready? We are waiting.", 
    sound: "file://sounds/message.mp3", 
    icon: "http://my.domain.de/avatar/user#id=123" 
}); 

请访问官方Reference进行更好的理解。

+0

像这样的东西就是我的意思:https://blog.pusher.com/how-to-send-ios-10-notifications-using-the-push-notifications-api/ – Sreinieren

+0

它用本地语言编码...所以我认为它很难找到相同的。对不起 –

+0

啊好吧没问题,谢谢你的努力! – Sreinieren