使用FirebaseAdmin通过Firebase Cloud Messaging发送Android消息

时间:2019-04-09 02:15:14

标签: c# asp.net firebase firebase-cloud-messaging

我已经尝试了好几天让FirebaseApp发送消息。请有人告诉我这里出了什么问题:

   FirebaseApp app = FirebaseApp.Create(new AppOptions()
    {
        Credential =GoogleCredential.FromFile(HttpContext.Current.Server.MapPath("~\\Services\\Messaging\\MY_app-12345.json")).CreateScoped("https://www.googleapis.com/auth/firebase.messaging")
    });



    public static async Task SendAsync(string deviceRegId, string message)
    {

    FirebaseMessaging fbMessage = FirebaseMessaging.GetMessaging(app);

        FirebaseAdmin.Messaging.Message m = new FirebaseAdmin.Messaging.Message
        {
            Token = deviceRegId,
            Android = new AndroidConfig()
            {
                Notification = new AndroidNotification()
                {
                    Body = message,
                    Title = "Title",
                    Sound = "bing"               
                },
                Priority = Priority.Normal,
            }
        };

            string response = await fbMessage.SendAsync(m);
            Console.WriteLine("Successfully sent message: " + response);
    }

永远不会越过fbMessage.SendAsyc并且应用程序永远不会收到消息。我看不到任何错误,什么也没有发生。谢谢!

0 个答案:

没有答案