【问题标题】:I am using Firebase in Chat Application when I send Message to my friend I am sending Push notification当我向朋友发送消息时,我在聊天应用程序中使用 Firebase 我正在发送推送通知
【发布时间】:2018-11-02 01:25:14
【问题描述】:

我在 Swift 中遇到以下错误,任何人都可以建议或提供解决方案。

SUCCESS: {
    error =     {
        code = 401;
        message = "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.";
        status = UNAUTHENTICATED;
    };
}

我正在使用 firebase 发送推送通知。

【问题讨论】:

  • 这是由于您没有告诉您的应用程序请求推送通知权限时引起的。您的应用正在尝试激活推送通知,但您的手机尚未授予您的应用使用推送通知的权限。

标签: iphone swift firebase firebase-realtime-database


【解决方案1】:
func sendPushNotification(message:String) -> ()
{
        let postParams = ["to":"Set here your receiver push id ","priority":"high","notification":["title":"Title","sound":"default","text":"YourMessage"]] as [String : Any]

        var request = URLRequest(url: URL.init(string: "https://fcm.googleapis.com/fcm/send")!)
        request.httpMethod = "POST"
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.setValue("key=getkey form firebase consol", forHTTPHeaderField: "Authorization")

        request.httpBody = try! JSONSerialization.data(withJSONObject: postParams, options: [])

        URLSession.shared.dataTask(with: request, completionHandler: { (responseData, response, responseError) -> Void in
            if response?.StatusCode == 200
            {
            }

        }).resume();
}

【讨论】:

  • 我认为您在标题中发送授权密钥时犯了错误
  • 当我收到推送通知时如何更新 AppIcon 徽章编号。我这样添加:["to":deviceID,"notification":["body":body,"title":title, "badge":1,"sound":"default"]] 为 [String:Any],但每次徽章编号仅显示 1。
猜你喜欢
  • 2012-10-26
  • 1970-01-01
  • 2014-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多