[英]PhonegapPluginPush - getting "OK" as push data
當應用程序被終止時,我們試圖從推送中獲取數據。
這里有一個堆棧信息:
Android: 8
device: Xiaomi Redmi 5
cordova: 7.1.0
cordova-android: 6.4.0
phonegap-plugin-push: 2.1.2
注冊和處理程序集
用戶注冊FCM令牌和 exec。 以下代碼。 最后
push.on('notification', (data) => {
.... statement_1
callbackA(data);
})
push.subscribe('notification', (data) => {
.... statement_2
// This statement is called only if
// app is closed and the user taps
// onto notification in the shade
})
由於 Android / App Closed 的問題,我們正在注冊和訂閱同一個“通知”事件。 (通常,如果用戶在應用程序被終止時點擊通知,則不會觸發“通知”事件 - 請參閱https://github.com/phonegap/phonegap-plugin-push/issues/2859 )
服務器推送請求示例
{
"registration_ids" : [ "...." ],
"priority" : 5,
"data" : {
"title" : "Push with URL",
"message" : "Questo invece è un esempio di push con un URL ",
"purpose" : "NEWS",
"id" : "2",
"notId" : 5,
"url" : "https://www.ciao.it/",
"actions":[
{
"title":"Accept",
"callback":"show",
"foreground":true
}
]
}
}
問題是現在,事件被正確觸發,但插件傳遞廣告數據“OK”字符串而不是推送兩個語句(1-2)的數據。
怎么了??
(僅供參考:正常場景[背景,前景]就像一個魅力!)
超級感謝提前
我們解決考慮 ADB logcat。
在app重新打開的過程中,很明顯監聽器是在插件的intent處理完之后注冊的。
所以,作為主“.run”模塊語句的第一行,我們把下面的代碼
$ionicPlatform.ready(function() {
if (ionic.Platform.isAndroid()) {
var push = PushNotification.init({
android: {}
});
push.on("notification", function(data) {
$$PushManager.init(data);
});
}
});
有了上面的行,我們就可以用負責它的服務來處理推送。
西蒙
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.