简体   繁体   中英

How to send FCM push notification to iOS using C#?

i need to send push notification to iOS. i have used below code to sending the push notification. this same code was used for sending the push notification to android. it has been worked fine. But using this same code for iOS, it does not working. I got a result is success but i am not received push notification in iOS device. I have tried to send the notification via FCM account, it has been sent to iOS. But while sending from server side it does not working.

                string serverKey = "234ddsd2424sdfcsfc3443cfsc";
                string FCMURL = "https://fcm.googleapis.com/fcm/send";

                string[] tokenId = { "dhr9oDxpEk8:APA91bEQkiwJ57s2NjgyjdvQDankXWXUiBQ95jiGYZNjtETu6M-uMVrRnh5VK2_Zh-TpkH4z5h51Nqm3WUn1sxsczHfvsAva17XE97BQbi2Lyd8-74aBKjLO8a7DE-s_1ry4pBcjQzRa" ,
                "dtBlERGdhA8:APA91bGhb5vOmGgkfwgCr-l4kuvNwthH0xsaH2uRyJBaYYIvYQNxEFg3KZWBeDcYPrJuL5yd5yPM6wW40tj7fy_JrsXDCUCuFP4SUU4wSwvhw7VqLQViUJWNWNEePn77i3Gvc1DSabN1"};

                WebRequest webRequest = WebRequest.Create(FCMURL);
                webRequest.Method = "post";
                webRequest.ContentType = "application/json";
                var objNotification = new
                {
                    registration_ids = tokenId,
                    data = new
                    {
                        title = "Test",
                        body = "Testing",
                        sound = "default",
                        icon= "CT_Logo.png"


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

                Byte[] byteArray = Encoding.UTF8.GetBytes(jsonNotificationFormat);
                webRequest.Headers.Add(string.Format("Authorization: key={0}", serverKey));
                webRequest.Headers.Add(string.Format("Sender: id={0}", serverKey));
                webRequest.ContentLength = byteArray.Length;
                webRequest.ContentType = "application/json";
                using (System.IO.Stream dataStream = webRequest.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);

                    using (WebResponse webResponse = webRequest.GetResponse())
                    {
                        using (System.IO.Stream dataStreamResponse = webResponse.GetResponseStream())
                        {
                            using (System.IO.StreamReader tReader = new System.IO.StreamReader(dataStreamResponse))
                            {
                                String responseFromFirebaseServer = tReader.ReadToEnd();
                                FCMResponse response = Newtonsoft.Json.JsonConvert.DeserializeObject<FCMResponse>(responseFromFirebaseServer);
                                if (response.Success>0)
                                {

                                }
                            }
                        }
                    }
                }

Have any solution to sending the push notification to iOS? Please reply me, if you know the answer for this.

试试这个仓库,它包含一个消耗FCM的.Net客户端: https : //github.com/bytefish/FcmSharp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM