Warm tip: This article is reproduced from stackoverflow.com, please click
apple-push-notifications django ios

App Download from App Store got BadDeviceToken, build from source does not

发布于 2020-04-23 14:57:12

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

Questioner
Sarit
Viewed
60
Sarit 2020-02-13 12:21

@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