针对ios的FCM自定义通知 [英] FCM custom notification for ios

查看:276
本文介绍了针对ios的FCM自定义通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经在android中问了很多时间而不是ios。所以我已经用FCM测试推送通知它工作正常。我的问题是如何创建自定义通知而不是让系统使用通知有效负载来处理通知?

I know this question have been ask a lot of time in android but not ios. So I already test out push notification with FCM it work fine. Mine problem is wether it's a way to create custom notification rather than letting the system to handle the notification with the notification payload?

推荐答案

对于使用c#工作代码的ios: -

For ios using c# working code:-

  public bool NotificationToiosDevice()
    {
        bool str;
        try
        {
            //Create the web request with fire base API  
            WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
            tRequest.Method = "post";
            //serverKey - Key from Firebase cloud messaging server  
            tRequest.Headers.Add(string.Format("Authorization: key={0}", "AAAALNl-P7o:APA91bE38khU73UTdIj7L6LvVS3uI6f47REmxl.................................."));
            //Sender Id - From firebase project setting  
            tRequest.Headers.Add(string.Format("Sender: id={0}", "12345"));
            tRequest.ContentType = "application/json";

            var payload = new
            {
                to = "dDDbFltwE5o:APA91bFmZZ-c1pNp................",

                priority = "high",
                content_available = true,
                notification = new
                {
                    title =  "Title Of Notification",

                },
                data = new
                {
                    body = new { Parameter1 = "FirstParameterValue", Parameter2 = "SecondParameterValue" },

                },
            };
            string jsonNotificationFormat = Newtonsoft.Json.JsonConvert.SerializeObject(payload);

            Byte[] byteArray = Encoding.UTF8.GetBytes(jsonNotificationFormat);
            tRequest.ContentLength = byteArray.Length;
            using (Stream dataStream = tRequest.GetRequestStream())
            {
                dataStream.Write(byteArray, 0, byteArray.Length);
                using (WebResponse tResponse = tRequest.GetResponse())
                {
                    using (Stream dataStreamResponse = tResponse.GetResponseStream())
                    {
                        if (dataStreamResponse != null) using (StreamReader tReader = new StreamReader(dataStreamResponse))
                            {
                                String sResponseFromServer = tReader.ReadToEnd();
                                // str = sResponseFromServer;
                            }
                    }
                }
            }
            str = true;
        }
        catch (Exception ex)
        {
            str = false;
        }
        return str;
    }

这篇关于针对ios的FCM自定义通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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