Why don't I receive iOS Push Notifications with a debug build connected to Xcode debugger? - swift

When I test the app using a TestFlight version built by the CI machine, the device receives push notifications.
But when I rebuild the app under Xcode locally with the debugger connected, the device doesn't receive any push notifications.
To validate things further I again tested locally with a push notifications tester, and the device indeed received a push notification.
So the code isn't omitted due to it being a #DEBUG build as the grant and registrations pass.
What is my local build possibly missing?

When you build your app in debug locally your app will generate a unique device token that doesn't receive production push notifications. When you build your app with a distribution provisioning profile it generates a different device token that does work on production.
Apple will reject a development device token unless you are specifically requesting a push notification using your APNS Sandbox certificate.
So if you haven't already you'll have to go through the certificate creation process all over again but this time for a sandbox certificate and use that one instead.

The solution ended up being that our server with the Houston gem needed to configure its APNS support to be in development mode, and not in production mode. 👍

Related

AWS Pinpoint: How to get notification when app install/run directly from Xcode into device?

We have created project in Mobile Hub and manage AWS Pinpoint to send push notification in iOS devices and setup AWS Pinpoint console for push notification. We have uploaded development certificate .p12 and download the demo app from our application(project) which is created using 'AWS Mobile Hub' web service(Screen shot attached). We are getting notification while installing it from adhoc IPA. But, We are unable to get notification when we are installing directly from Xcode into my device.
So, how to get notification when app install/run directly from Xcode ?
Thanks
Previously, the Pinpoint console didn't support sending push notifications via the APNs Sandbox development environment.
Note: This feature was supported earlier only by invoking the API (not through the console). You can make a call to the API to do the following:
To register the APNs Sandbox Channel.
Register a device as an APNs Sandbox endpoint.
Send messages/campaign pushes to it.
As of yesterday (10/03/2017) Pinpoint fully supports APNs Sandbox environment through the console as well. In order to register a device as an APNs Sandbox endpoint, use the latest version of the AWS iOS SDK (v2.6.2 or above) and enable the debug flag. This corresponds to the Sandbox development environment.
You can enable the debug flag by using the following code snippet
AWSPinpointConfiguration *config = [AWSPinpointConfiguration defaultPinpointConfigurationWithLaunchOptions:launchOptions];
[config setDebug:YES];
AWSPinpoint *_pinpoint = [AWSPinpoint pinpointWithConfiguration:config];

Push notification on production mode not receiving PNS

I am new to PNS. I have developed one app which is having PNS and deliver ipa to client and PNS coming properly no issues at all in development mode.Now i want to uplaod to App store before that i am creating all new certificate and profiles in production mode and tested from server but in Production mode PNS is not coming?? I have removed sandbox from PHP server side script even replaced .pem certificate name also. but still not working. Any idea what is going wrong??
You need to run a distribution version of your app, e.g. built against a distribution provisioning profile, one of Ad Hoc/Enterprise/AppStore. Make sure the profile has a production push notification entitlement.
You can check this with
codesign -d --entitlements - pathTo.app
look for
<key>aps-environment</key>
<string>production</string>

AdHoc build receives no push notifications

I am developing push notifications for an app of mine, I wrote the provider in PHP and it works fine. I was previously testing the push notifications with my dev builds and the sandbox server from Apple and everything worked fine, now I am trying to get it to work with an AdHoc build but I never receive any messages on the phone. Here is what I did:
Enable production push notifications for the App, create the certificate, download it, create the PEM following the instructions here and upload it to my server. Configured my PHP Script to use gateway.push.apple.com and port 2195 for the connection and test it, the connection to the server works as expected.
The Layout of the payload is the same as with the dev and writing to the stream works
After activating Production APN I recreated my AdHoc provisioning profile and verified after the build that in the entitlements aps-environment is set to "production" (which it is)
Installed the App through AdHoc on a device which has not run the app before, I get asked whether to allow PNs, click yes and my server receives the token just as it should.
Tried to send a message (which should get send to 3 devices) through the production environment. There is no error when connecting to Apple or sending the data but I do not receive a push notification on any of the devices.
I am really out of ideas what could be wrong, does anybody have an idea? Thanks a lot!
I finally figured this out, the issue is that if you open a connection to the APNS and send over more than one push notification AND one of the tokens you submit is not a token valid for this certificate (eg. you send over a token that belongs to a dev instance whilst being connected with the production certificate) the APNS cancels the delivery of all the PNs that you sent in this batch. At least that is what I experienced so far, so make sure you always keep your dev and production tokens nicely separated :)
Push certificates for production and development are different. And to make more difficult device tokens for production and sandbox are different for the same device. Cross check if these are correct and Im sure you must have faltered in this. To get device token in Production mode, write an alertview in AppDelegate didreceivenotifications event.
Once you get this token, you will know that it is different from dev token that we are generating which is why you were not able to send notification on PROD
I am struggling with the same issue. I believe the problem is that with adhoc builds, apple will only send notifications to them from the production apns server, try that.
For distribution and release build always use production certificate.

How do I debug production push notifications using Xcode?

I would like to be able to debug handling of push notifications that originate from the production environment using Xcode. However, it appears that only distribution provisioning profiles can be used with an aps-environment entitlement value of "production". Is there a way to debug production messages on the device using Xcode?
You should use the development push certificates for this. Send your push notifications to ssl://gateway.sandbox.push.apple.com:2195 rather than ssl://gateway.push.apple.com:2195
Refer to Apple Documentation for more info.

iPhone APNS Device Tokens in sandbox vs. production

How do device tokens vary from sandbox to production modes?
I think I have locked up some device tokens into a production mode, and they can't be pushed to from development.
Any ideas on how I can check?
When you build your app using a development cert, the app will generate a unique device token. This device token will not work on the production push network. When you then build your app with a distribution provisioning profile (App Store or Ad-Hoc) your device will generate a different device token for push notifications. If you try to send the development generated token to the production push SSL network, Apple's servers will reject your token.
What I did was to try production first, then if that failed with an InvalidToken code, then try it again against sandbox.
In case you're wondering, yes, this is harder than it needs to be.