在Firebase中发送徽标的功能

时间:2019-05-29 13:59:56

标签: ios swift firebase

当我使用使谈话成为可能的代码进行操作时,我可以和这个班见面吗?帮助我参加一个好的班级,发送标语或知道该班级的错误。

this.db.list

激活码

import UIKit
class FirebaseM  {
func sendPushNotification (notData: [String: Any]){

    let url = URL(string: "https://fcm.googleapis.com/fcm/send")!
    var request = URLRequest(url: url)
    request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
    request.setValue("application/json", forHTTPHeaderField: "Accept")
    let serverKey = "key=AAAA_XXXXXXXXXXX"
   request.setValue (serverKey, forHTTPHeaderField: "authorization")
    request.httpMethod = "POST"
    request.httpBody = try? JSONSerialization.data(withJSONObject: notData, options: [ ])
    let task = URLSession.shared.dataTask(with: request) { data, response, error in
        guard let data = data, error == nil else {
            print ( "1:",error ?? "")
            return
        }
        if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {
            print ("statusCode should be 200, but is \(httpStatus.statusCode)")
            print (response ?? "")
        }
        let responseString = String(data: data, encoding: .utf8)
        print (responseString ?? "")
    }
    task.resume()
}
}

0 个答案:

没有答案