-
-
Save kylebrowning/240be40a92bf219481f05dd3f4bc9c94 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application( _ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { | |
let tokenParts = deviceToken.map { 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: "http://172.20.3.158:9090/devices")!) | |
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 { | |
print(error) | |
} else { | |
print(data) | |
} | |
}).resume() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment