step by step implementation of nativescript push notification in nativescript

耗尽温柔 提交于 2020-01-17 16:57:09

问题


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));
      });
    },

the response is as below.

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: }

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


回答1:


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.

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

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!

Tip: Make sure your project number exactly matched your Firebase project value.

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);
        }
    };


来源:https://stackoverflow.com/questions/54364402/step-by-step-implementation-of-nativescript-push-notification-in-nativescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!