Hello everyone!
I am trying to implement push notifications in my WatchOS app. I have created the delegate class that handles the registration for remote notifications and that allows me to obtain the device token. Then I take the token and send it to Firebase, like this:
func didRegisterForRemoteNotifications(withDeviceToken deviceToken: Data) {
FirebaseApp.configure()
var ref: DatabaseReference!
ref = Database.database().reference().ref.child("/")
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
if let userID = UserDefaults.standard.object(forKey: "id") as? String {
ref.child("users/\(userID)/token").setValue(token)
}
}
Then I am using a Python Script to communicate with APNS. I am using the http library to get access to HTTP2. This is what I have got:
payload = {
"aps" : {
"alert" : {
"title" : "Hello Push",
"message": "This is a notification!"
},
"category": "myCategory"
}
}
dev_server = "https://api.sandbox.push.apple.com:443"
device_token = "9fe2814b6586bbb683b1a3efabdbe1ddd7c6918f51a3b83e90fce038dc058550"
headers = {
'method': 'POST',
'path': '/3/device/{}'.format(device_token),
'autorization': 'bearer' + 'provider_token',
'apns-push-type': 'myCategory',
'apns-expiration': '0',
'apns-priority': '10',
}
async def test():
async with httpx.AsyncClient(http2=True) as client:
client = httpx.AsyncClient(http2=True)
r = await client.post(dev_server, headers=headers, data=payload)
print(r.text)
asyncio.run(test())
I have also downloaded the .p8 auth key file. But I don't really understand from the Apple Documentation what I have to do with it.
What is the provider token in the headers?
Am I doing the right thing with the token I receive from didRegisterForRemoteNotifications?