Ionic 如何在FCM离子通知中显示图像

prdp8dxp  于 2022-12-08  发布在  Ionic
关注(0)|答案(2)|浏览(169)

HI我正在使用 cordova 插件“FCM”推送通知,我能够显示通知的文本,当从服务器推送通知时,事情工作正常,但我不能显示图像,我有一个包含图像的jpg格式的URL,有人能告诉他如何显示图像吗
我导入了
import { FCM } from '@ionic-native/fcm';

if (device.platform == "Android" || device.platform == "iOS") {
    fcm.getToken().then(token => {
    //console.log("FCM Token generation :: " + token);
    fcm.onNotification().subscribe(data => {
      if (data.wasTapped) {
        //  console.log("onNotification", JSON.stringify(data))
                        }
    else {
        //  console.log("onNotification", JSON.stringify(data))
        }
    });

}

我需要显示图像,有人能帮我吗
这是我的c#代码,我用来把数据推到firebase控制台

var fcmUrl = "https://fcm.googleapis.com/fcm/send";

       var serverKey = "serverKey";

        var senderId = "9866455";



        string sResponseFromServer = string.Empty;


        try

        {

            //WebRequest request = WebRequest.Create(fcmUrl);


            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fcmUrl);

            request.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

            request.Method = "post";

            request.ContentType = "application/json";

            var data = new

            {

                to = "/topics/test2",

                notification = new

                {

                    title = "Notification With Image",

                    body = " Message from Data",                        

                    image = "https://abcdedd.com/assets/images/loginheaderlogo.png"                      

                }


            };


            var json = JsonConvert.SerializeObject(data);

            Byte[] byteArray = Encoding.UTF8.GetBytes(json);

            request.Headers.Add(string.Format("Authorization: key={0}", serverKey));

            request.Headers.Add(string.Format("Sender: id={0}", senderId));

            request.ContentLength = byteArray.Length;

            request.Proxy = WebRequest.DefaultWebProxy;

            request.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;


            using (Stream dataStream = request.GetRequestStream())

            {

                dataStream.Write(byteArray, 0, byteArray.Length);

                using (WebResponse tResponse = request.GetResponse())

                {

                    using (Stream dataStreamResponse = tResponse.GetResponseStream())

                    {

                        using (StreamReader tReader = new StreamReader(dataStreamResponse))

                        {

                            sResponseFromServer = tReader.ReadToEnd();

                        }

                    }

                }

            }

            var result = JsonConvert.DeserializeObject(sResponseFromServer);

            Console.WriteLine(result.ToString());

        }

        catch (Exception ex)

        {

           var e = ex.Message;

            Console.WriteLine(ex.ToString());

        }
envsm3lx

envsm3lx1#

对于节点:工作示例:

var FCM = require('fcm-node');
    var serverKey = 'asdf-asdf'; //put your server key here
    var fcm = new FCM(serverKey);

    var message = { //this may vary according to the message type (single recipient, multicast, topic, et cetera)
        to: 'asdf-asdf', // your device Token        
        notification: {
            title: 'Notification Title', 
            body: 'Notification body',
            image: 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png' // your image URL
        },

        data: {  //you can send only notification or only data(or include both)
            my_key: 'my value',
            my_another_key: 'my another value'
        }
    };

    fcm.send(message, function(err, response){
        if (err) {
            console.log("Something has gone wrong!");
        } else {
            console.log("Successfully sent with response: ", response);
        }
    });
fykwrbwg

fykwrbwg2#

{
    "to": "daOTkMyqSx2d21pdlwF8hf:APVhjLosE1J7tvPss5zEgYzH4Pb6RDSaudogrtaJpKIz5U9wDop6CLQoKAU3VAWQKlC_aUxVCLjxlFRwA91bGJkqRAPFuSj24vLd06rtk1MZrGaMcl5z7FUGSxGYlv2BN2qcRIqpCJX-",
    "notification": {
        "title": "Sparky says hello! 😀 😃 😄 😁 😇 🙂 🙃 😉 😌 😍 🥰",
        "body": "Sparky says hello! 😀 😃 😄 😁 😆 😇 🙂 🙃 😉 😌 😍 🥰",
        "image": "https://testdemo.com/images/notifications/513/1665046325658gifEx.gif",
        "type": "BIGPIC",
        "icon": "drawable_land_ldpi_screen",
        "data": {
            "url": "https://testdemo.page.link/8EjcD5cQ2ycxqnKQpVA"
        }
    }
}

这是我们可以从 Postman 处检查的通知内容,以便在通知上显示图像。您必须在清单文件中为此**https://testdemo.page.link**url添加intent-filter

相关问题