2016-11-16 212 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