在nativescript中逐步实现nativescript推送通知 [英] step by step implementation of nativescript push notification in nativescript

查看:38
本文介绍了在nativescript中逐步实现nativescript推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以从创建helloworld应用开始逐步提供指导,然后其余步骤进行推送通知.我已经通过下面的链接,但未能实现 https://github.com/EddyVerbruggen/nativescript-plugin-firebase

can anyone give step by step guidence starting from creating a helloworld app then the remaining steps to do push notifications. i have already gone through the below link and failed to achieve that https://github.com/EddyVerbruggen/nativescript-plugin-firebase

我对此有一些进展,请参见下面的代码.

i have some progress on it, refer below code.

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.

even it says success. i have not got any notification on android. i'm not using ios.

推荐答案

我在这里很陌生,但是我意识到,如果您在此处发布Nativescript代码以及您的问题,您更有可能找到解决问题的方法.这样,我们可以查看您的代码在哪里失败.关于此插件,我将告诉您命令性是您遵循自述文件文件.我也有一段时间想让它开始工作,但是现在我有了推送通知了.

I am fairly new here, but I realized you are much more likely to get a solution to your problem if you post your Nativescript code here, along with your questions. That way, we can look to see where your code is failing. Regarding this plugin, I will tell you it is imperative you follow every step in the readme file that comes with the plugin. I also had a heck of a time getting this to work, but now I have push notifications working.

以下是运行中的NativeScript推送通知的示例.该应用程序还将教您如何实现推送通知.这些是我遇到过的最好的推送通知. NativeScript推送通知示例

Here is an example of NativeScript push notifications in action. This app will also teach you how they achieved their Push Notifications. These are the nicest Push Notifications I have run across yet. NativeScript Push Notification Examples

请在您的页面XML和js代码后面加上代码,我们将进行看看.另外,请确保正确设置此值,因为这让我头疼.祝您好运,发布您的代码,以便我们提供帮助!

Please post your page XML and js code-behind, and we'll have a look. Also be sure this value is set properly, as this caused me a headache. Good luck, post your code so we can help!

提示:请确保您的项目编号与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);
        }
    };

这篇关于在nativescript中逐步实现nativescript推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆