Explorar el Código

pass token to notification server

B. Petersen hace 4 años
padre
commit
76e6119ffc
Se han modificado 1 ficheros con 18 adiciones y 4 borrados
  1. 18 4
      deltachat-ios/AppDelegate.swift

+ 18 - 4
deltachat-ios/AppDelegate.swift

@@ -301,10 +301,24 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
       _ application: UIApplication,
       didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data
     ) {
-      let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
-      let token = tokenParts.joined()
-      print("Device Token: \(token)")
-      // TODO: pass token to provider
+        let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
+        let tokenString = tokenParts.joined()
+        print("Device Token: \(tokenString)")
+
+        if let url = URL(string: "https://notifications.delta.chat/register?token=\(tokenString)") {
+            var request = URLRequest(url: url)
+            request.httpMethod = "POST"
+            //let param = "token=\(tokenString)"
+            //request.httpBody = param.data(using: String.Encoding.utf8)
+            let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
+                if let error = error {
+                    logger.error("cannot POST to notification server: \(error)")
+                    return
+                }
+                logger.info("request to notification server succeeded with respose, data: \(String(describing: response)), \(String(describing: data))")
+            }
+            task.resume()
+        }
     }
 
     func application(