Invalid DeviceToken Length when sending passkit push by PushSharp
Asked Answered
G

1

12

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...

Gentoo answered 14/11, 2016 at 18:12 Comment(1)
Have you already taken a look at this issue?Frans
D
8

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);
Devilment answered 17/11, 2016 at 16:31 Comment(6)
Also make sure to use the right certificate (which seems to be different from the certificate for regular push notifications) and test this with the production certificate as there seems to be no sandbox environment for passbook (see this answer).Devilment
Thanks guys! I'll try your code, and certificate is OK, it is 100%.Gentoo
I tried, it fixed this problem, but another occurs. Pls. check my updates in my question. Thanks a lot!Gentoo
@Tom: Try passing 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);Devilment
It is set to falseGentoo
@Tom: I don't know what the problem could be other than that, have a look at this question, maybe there is some useful information for you, altough that user used an older PushSharp version...Devilment

© 2022 - 2024 — McMap. All rights reserved.