Push notifications do not work for Apple Store's app version

Dear all,


My iOS application is registered for receiving push notifications from a server. My AppDelegate.m inherits the

UNUserNotificationCenterDelegate

and it uses the

didRegisterForRemoteNotificationsWithDeviceToken

method.


In the server side, I used the Java-APN library (https://github.com/CleverTap/apns-http2). By this library, the server is able to send push notifications to the iOS devices.


I tested the application in many iPhone devices with iOS version 11.6 to 12.2. The push notifications are sent properly to the iOS devices before I upload the application to Apple Store.


After the application was successfully reviewed and it was available on Apple Store, I downloaded and run it on iOS devices. Unfortunately, the application does not receive any push notification. I checked this issue by sending push notification manually using the device token was created, after the application was downloaded from Apple Store. I got “BadDeviceToken” although it seems ok to me the device token in the aspects of its string size.


Meanwhile, if I connect any iOS device to my Mac and run the application from Xcode, then the application receives properly the push notifications from the server. The generated device token is valid.


Do you have any idea why the push notification is not received by the application when it is downloaded from the Apple Store?


Regards,

Replies

Dear all,


I have uploaded two more versions in Apple Store but unfortunately still the same.

The device token which is generated when the app is downloaded from Apple store, it is "BadDeviceToken".


Just to mention that the length of the device token which is generated when the app is downloaed from Apple Store is equal to the length of the device token which is generated when the app is downloaded from Xcode (version 10.2.1).


Is it related to any Apple Store policy issue?


I really appreciate any help.


Regards

Is your .entitlements file entry for APS Environment set to 'development' or 'production'?

Thanks for your point.


I changed my .entitlements file entry for my APS Environment from 'development' to 'production'.


<dict>
  <key>aps-environment</key>
  <string>production</string>
</dict>


However, I still receive “BadDeviceToken” when I try to send a push notification.


Regards,

Is it possible that your token is valid for the development environment and not valid for the production environment?


You wrote:

"I tested the application in many iPhone devices with iOS version 11.6 to 12.2. The push notifications are sent properly to the iOS devices before I upload the application to Apple Store."


You can test Xcode installed builds with the entitlements saying 'development' (you said it worked above) and then with the entitlements saying 'production'. If your token works for one and not the other then that may be the problem.

I tested from Xcode installed builds with .entitlements 'development' and 'production'. Both of them worked properly, I received push notitifcations successfully.


The problem is with the Apple Store version. I receive “BadDeviceToken” when I try to send a push notification.


Regards,

Do you have any idea to try it?


Reagrds,

Unfortunately I do not. If your entitlements is pointing to production and the system works when run from Xcode I do not know what would be different in the App Store version.

I revoked and re-generated all the appropriate certificates again.


From my Xcode 10.3 (10G8) (Mojave version 10.14.6) , if I changed manually the aps environment from development to production value and then build the application. As a result, I saw "Add the Push Notifications entitlements to your entitlement file" and "Fix issue" in the capabilities tab of my app's target. If I click on "Fix issue", then the aps environment is automatically changed to development. Searching on it, I realised that there was a problem (in the past?). I tried some proposed solutions without result e.g. create two entitlements files,one for development and one for production and declare the in "Code Signing Entitlements" at app's target "Build Settings", I disabled and re-enabled "Push notifications" in capabilities etc.


"Xcode sets the value of the entitlement based on your app's current provisioning profile. For example, if you're using a development provisioning profile, Xcode sets the value to

development
.", as it is mentioned at https://developer.apple.com/documentation/bundleresources/entitlements/aps-environment?language=obj .


My distribution profile seems to work properly because I can upload new versions of my application to Apple Store.

My development profile also works properly. I can download my applications from Xcode to iOS devices.


When I create an archive and validate it, my app's .ipa contents include summary and entitlements information.

In the entitlements section, the aps-environment has set to production, either if I am using my developer account (it set by checking "Automatically manage signing" in my app's target at General tab) or my distribution account (uncheck the "Automatically manage signing" and select the "distribution" profile).


From my java apns server, I can send push notification successfully only with development certificates.

If I try with production certificates. I receive httpStatusCode=400, responseBody='{"reason":"MissingTopic"}', which means "The

apns-topic
header of the request isn't specified and is required. " as it is mentioned at https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns?language=objc

which I cannot understand at all what do I have to do.


Regards,

I changed the topic in my apns server to my app's bundle identifier and it worked.

It is clearly stated at https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns?language=objc

in the section "Create and Send a POST Request to APNs".

How doesn't this have a solution?