1

I have searched over the Stackoverflow, but none of them answer to my questions Build from Xcode APNS works, but App Store version my backend raises BadDeviceToken.

The Success are registration_id made by build from source

In [1]: APNSDevice.objects.all().send_message("test")
Out[1]:
[{'27321a3d872613499e27638733e9d1da7e6aa52888a2d90769b150f6339360b1': 'Success',
  '798a23a46169e405c41a0c9f44faa0acd39a65119960b973acd248a6de1d624e': 'Success',
  '1d742a9ae1684fed5e6c672587ee27c1523cc97e931cc64f108f7c4924aba2af': 'DeviceTokenNotForTopic',
  '27173de1aed3a065644708602fd5659cf4e0f8c3ce5b3ef7c4b0769655b92041': 'DeviceTokenNotForTopic',
  'e5647247877a0e1db3c7b52821b4230551267ca8a360f862ec5dde506e9b2f36': 'Success',
  '0eecae0cb6f4c27ee4b915e37dbb9c7cc84e4967e71c8efab808e231f46b8ec6': 'BadDeviceToken',
  '582d6a7c4628131cba9d0dfa9096cc81e3b48f6b6409252515d7402ef1c3ef30': 'BadDeviceToken'}]

I don't care DeviceTokenNotForTopic for now. Just stay focus on BadDeviceToken

Step to reproduce are:

  1. Follow this to get .p12 file
  2. Then make .pem from doc. I must put passphrase to key otherwise I can not proceed next step
  3. Download my own app from App Store and login to get registration_id

Checkings:

  1. pushtry.com I upload .p12 and put registration_id. It works I can get push notification

  2. openssl s_client -connect gateway.push.apple.com:2195 -cert aps-cert.pem -key aps-key-noenc.pem also works without any problem. The connection still remain

My configuration:
Django3
django-push-notification @master commit: c610dd9c7871f4e81bdffce783df8b040ca22878

settings.py

PUSH_NOTIFICATIONS_SETTINGS['APNS_CERTIFICATE'] = str(APPS_DIR) + '/push_noti/dd/aps.pem'
PUSH_NOTIFICATIONS_SETTINGS['APNS_USE_SANDBOX'] = "gateway.push.apple.com:2195"
PUSH_NOTIFICATIONS_SETTINGS['APNS_TOPIC'] = "com.multy.herr.reviews"

I had tried with the same production APNS cert according to this

Development server: api.sandbox.push.apple.com:443
Production server: api.push.apple.com:443

However, all giving me same BadDevieToken

FYI:
I am using production APNS cert

I take care only Django backend. My iOS developer upload app from his computer. I am not sure this will be problematic or not

I had tried fastlane with pushtry.com again .p12 works, but .pem does not. It pop up dialog production_com.xxx.yyy.zzz.pem | 3883 | application/x-x509-ca-cert

Question:

Where am I wrong?

Another Solution:
I might use AWS SNS to deal with this

joe
  • 8,383
  • 13
  • 61
  • 109
  • I found this one, urging my iOS developer confirm this answer https://stackoverflow.com/questions/12660931/cant-register-for-push-notifications-while-using-production-certificate-only/12670448#12670448 – joe Feb 11 '20 at 03:40

2 Answers2

1

As noted in the README for django-push-notification:

If you are planning on running your project with APNS_USE_SANDBOX=True, 
then make sure you have set the development certificate as your APNS_CERTIFICATE.

So the issue is with the line:

PUSH_NOTIFICATIONS_SETTINGS['APNS_USE_SANDBOX'] = "gateway.push.apple.com:2195"

For more information on the difference between using APN for debug vs release builds of an app you should read iOS APNS Development [sandbox] vs Production

Wyetro
  • 8,439
  • 9
  • 46
  • 64
  • Thank you for your attention. I am using `prod` APNS and I had tried 2 more different APNS url according to this https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns/ Development server: api.sandbox.push.apple.com:443 Production server: api.push.apple.com:443 – joe Feb 11 '20 at 03:23
1

@Wyetro is correct. The problem comes from that line I was confused with document and codebase at certain level in the lib itself it use bool

PUSH_NOTIFICATIONS_SETTINGS['APNS_USE_SANDBOX'] = False

Then I can be able to send out message

joe
  • 8,383
  • 13
  • 61
  • 109