I try to use PushSharp in an Apple passkit related project.
My current problem is about passkit pushes.
When I try to create my notification, it says
device tokent length is invalid (exact exception message: Invalid DeviceToken Length.
var notif = new ApnsNotification(token, payload);
When I register a new passkit coupon, its token length is 32. It seems ok for me.
What should be the problem? Does PushSharp support passkit at all? As I see, some people used it, but I could not find any Official info about it.
Please note, I know PushSharp as I use it to send Normal push messages, it has been working for years without any problem for me. My question is about passkit-related pushes.
Thanks very much!
EDIT
After changing the code by Baris Akar's suggestions, the problem is fixed, but another comes:
Apple Notification Failed: ID=1, Code=ConnectionError
2016-11-18 11:07:22.de. [INFO] Stopping: Waiting on Tasks 2016-11-18 11:07:22.de. [INFO] Waiting on all tasks 1 2016-11-18 11:07:22.de. [INFO] APNS-Client[1]: Sending Batch ID=1, Count=1 2016-11-18 11:07:22.de. [INFO] APNS-Client[1]: Sent Batch, waiting for possible response... Apple Notification Failed: ID=1, Code=ConnectionError 2016-11-18 11:07:22.de. [INFO] All Tasks Finished 2016-11-18 11:07:22.de. [INFO] Passed WhenAll 2016-11-18 11:07:22.de. [INFO] Broker IsCompleted 2016-11-18 11:07:22.de. [DEBUG] Broker Task Ended 2016-11-18 11:07:22.de. [INFO] Stopping: Done Waiting on Tasks 2016-11-18 11:07:22.de. [INFO] APNS-Client[1]: Done Reading for Batch ID=1, reseting batch timer...
In seems like in an older version, it would have worked like this:
var n = new AppleNotification().WithPasskitUpdate();
The function WithPasskitUpdate()
is not available anymore, but this should be the equivalent:
var notif = new ApnsNotification();
notif.DeviceToken = token;
notif.Payload = payload;
Didn't test it, but after checking the code, maybe it could work. Basically you are bypassing the token length check in the ApnsNotification
constructor this way (which should be probably fixed, if the token is smaller for passkit pushes).
Also make sure to use the right certificate (which seems to be different from the certificate for regular push notifications) and use production settings as there seems to be no sandbox environment for passbook (see this answer).
Moreover, you need to pass false
for the validateIsApnsCertificate
parameter of the ApnsConfiguration
constructor, since there is a check for the certificate which doesn't handle the pushkit certificate.
var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, certificateFile, certificateFilePwd, false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With