Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \(token)")
sendDeviceToken(device: Device(platform: "ios", deviceToken: token))
struct Device: Codable {
var platform: String
var deviceToken: String
func sendDeviceToken(device: Device) {
var request = URLRequest(url: URL(string: "")!)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
request.httpBody = try? JSONEncoder().encode(device)
URLSession.shared.dataTask(with:request, completionHandler: {(data, response, error) in
if error != nil {
} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.