任何人都可以从创建helloworld应用程序开始逐步提供指导,然后其余步骤进行推送通知。 我已经通过下面的链接,但未能实现 https://github.com/EddyVerbruggen/nativescript-plugin-firebase
我对此有一些进展,请参见下面的代码。
http.request({
url: 'https://fcm.googleapis.com/fcm/send',
method: "POST",
headers: { 'Authorization': 'key=AIzaSyBri16HAa7g2REEy******YFnTDGIlM_1k', 'Content-Type': 'application/json' },
content: JSON.stringify({
"notification": {
"title": "testingtesting",
"text": "some text",
"sound": "default",
"click_action": "GENERAL",
"badge": "1",
"showWhenInForeground": true
},
"content_available": false,
"data": {
"foo": "bar"
},
"priority": "High",
'to': "AAAACcS8hG0:APA91bEonX87xRfBHvccNheOR2ppFHZKaFlGGm6PRF6eEEYZg5Gd7uU_OU0GRJ0MkiTrR2gSDGO7Nz6BByujX4ex1jGgKpO20SXcGMa78k405vNV_4uJ1UDk_b-0-regi5x96KRcaOMH"
})
}).then((response) => {
//HttpResult = response.content.toJSON();
console.log('----------------------------------------------------');
console.log(response);
}, (e) => {
console.log("Error occurred " + JSON.stringify(e));
});
},
响应如下。
JS: ----------------------------------------------------
JS: {
JS: "content": {
JS: "multicast_id": 5720873045813109000,
JS: "success": 1,
JS: "failure": 0,
JS: "canonical_ids": 0,
JS: "results": [
JS: {
JS: "message_id": "0:1548488437363910%0000000000000000"
JS: }
JS: ]
JS: },
JS: "statusCode": 200,
JS: "headers": {
JS: "null": "HTTP/1.1 200 OK",
JS: "Alt-Svc": "quic=\":443\"; ma=2592000; v=\"44,43,39\"",
JS: "Cache-Control": "private, max-age=0",
JS: "Content-Encoding": "gzip",
JS: "Content-Type": "application/json; charset=UTF-8",
JS: "Date": "Sat, 26 Jan 2019 07:40:37 GMT",
JS: "Expires": "Sat, 26 Jan 2019 07:40:37 GMT",
JS: "Server": "GSE",
JS: "Transfer-Encoding": "chunked",
JS: "X-Android-Received-Millis": "1548488436596",
JS: "X-Android-Response-Source": "NETWORK 200",
JS: "X-Android-Selected-Protocol": "http/1.1",
JS: "X-Android-Sent-Millis": "1548488436437",
JS: "X-Content-Type-Options": "nosniff",
JS: "X-Frame-Options": "SAMEORIGIN",
JS: "X-XSS-Protection": "1; mode=block"
JS: }
JS: }
甚至说成功。我没有在Android上收到任何通知。我没有使用iOS。
答案 0 :(得分:-1)
我在这里还很陌生,但是我意识到,如果您将Nativescript代码和问题一起发布在这里,那么您更有可能找到解决问题的方法。这样,我们可以查看您的代码在哪里失败。关于此插件,我将告诉您,命令性是您遵循该插件随附的readme文件中的每个步骤。我也很想让它开始工作,但是现在我有了推送通知。
以下是运行中的NativeScript推送通知的示例。该应用程序还将教您如何实现推送通知。这些是我遇到过的最好的推送通知。 NativeScript Push Notification Examples
请在您的页面XML和js代码后面加上代码,我们将进行看看。另外,请确保正确设置此值,因为这让我头疼。祝您好运,发布您的代码,以便我们提供帮助!
提示:请确保您的项目编号与Firebase项目值完全匹配。
var pushSettings = {
senderID: "<ENTER_YOUR_PROJECT_NUMBER>", // Required: setting with the sender/project number
notificationCallbackAndroid: function (stringifiedData, fcmNotification) {
var notificationBody = fcmNotification && fcmNotification.getBody();
_this.updateMessage("Message received!\n" + notificationBody + "\n" + stringifiedData);
}
};