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

mmushtaq
  • 3,058
  • 7
  • 28
  • 42
Tom
  • 3,349
  • 20
  • 73
  • 131

1 Answers1

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);
Community
  • 1
  • 1
Baris Akar
  • 4,755
  • 1
  • 23
  • 54
  • 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](http://stackoverflow.com/a/30493091/594074)). – Baris Akar Nov 17 '16 at 16:37
  • Thanks guys! I'll try your code, and certificate is OK, it is 100%. – Tom Nov 18 '16 at 09:21
  • I tried, it fixed this problem, but another occurs. Pls. check my updates in my question. Thanks a lot! – Tom Nov 18 '16 at 10:10
  • @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);` – Baris Akar Nov 21 '16 at 12:08
  • It is set to false – Tom Nov 21 '16 at 12:18
  • @Tom: I don't know what the problem could be other than that, have a look at [this question](http://stackoverflow.com/questions/30381106/sending-passbook-update-with-pushsharp), maybe there is some useful information for you, altough that user used an older PushSharp version... – Baris Akar Nov 21 '16 at 13:33