AdHoc build receives no push notifications - iphone

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.

Related

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

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. đź‘Ť

apns push notifications is not working with production certificate

I've enabled push notifications for my App ID and checked in development that is fine, but in production i am not getting notifications.
I used the following code in my server side.
Here are the steps I have followed when switching from production to development:
used the production SSL certificate key
changed the sandbox to false in above blog
I cross checked my distribution provisioning profile which contains key aps-environment and production mode
Is there any thing still I need to change, how can I cross check where I am going wrong?
I already downloaded my app from iTunes portal, but I did keep my .p12 file in my project while archiving, is it necessary?
Device tokens are different for development and production environment. Production device tokens are invalid in development environment and vica versa. You should have maintained different databased for the production tokens and development tokens. Now that you have them mixed it's a bit tricky to tell them apart.
You can find out which device token are invalid in the production environment (which means they are probably development tokens) by sending notifications for all your device tokens. After each send you should try to read an error response from Apple. Error response 8 means invalid device token. You should use a long timeout for that read (since it sometimes takes time to get the error response from Apple).

apple push notification not working in production

We are totally stucked, please help.
I and my team made a iPhone application, and this is the first time we try on iOS.
Everything is fine, until we submitted our app and became available on app-store -- the push notification service is not working. I searched around the web and tried double check on our app by people's advices, but I couldn't find what's wrong. so this question is posted here.
These are what we did:
We build the application, suppose it's named "AppMaster".
We created AppId on iOS Provisioning Portal called: "pushtest". This ID enabled the Push Notification on both development and production.
We created a Provisioning for development named "AppMasterPushTest" from the appId above. This provisioning is for inside test, everyone of the team installed it on their mac.
Our server is implemented by Java and we used the java-apn package. during the test, We downloaded the certification file for development and write out the .p12 file, and pushed our message to the "sandbox" server by using the package's api -- withSandboxDestination() with that .p12 file. test goes fine, notifications are received.
I thought we were ready, so we created another AppId called "AppMaster", and enable Push Notification only for production. This Id is written in the app's bundle identifier.
We made another Provisioning for production named "appMaster" from AppId in step 5, with distribution method set as "App Store". downloaded it and rebuild app. This one was submitted to apple, and goes alive on app-stroe.
Server side, We downloaded the certification for production and write out the .p12 file again. and made program to push message to production server by using the api -- withProductionDestination(), with the .p12 just been write out.
We installed the app from App Store. sadly, the notification was never delivered.
Is there something we missed? BTW, the id we created in step5 was looks like "XXX.com.company.appname", but in the app's bundle identifier, we just set "com.company.appname" part without prefix. is this could be the problem?
any idea is welcomed.
please be our saver. thanks.
The comment above is incorrect. The app ID has a prefix before the bundle ID :
An application ID consists of an application’s bundle ID prefixed with
a ten-character code generated by Apple. The team admin must enter the
bundle ID. For a certificate, it must incorporate a specific bundle
ID; you cannot use a “wildcard” application ID.
You should check your provisioning profile, to make sure it contains the correct aps entitlement :
Verify that the entitlements in the provisioning-profile file are
correct. To do this, open the .mobileprovision file in a text editor.
The contents of the file are structured in XML. In the Entitlements
dictionary locate the aps-environment key. For a development
provisioning profile, the string value of this key should be
development; for a distribution provisioning profile, the string value
should be production.
You should make sure you are using production device tokens when sending push notifications to the production APNS server (device tokens that works in the sandbox environment don't work in the production env).
You should have tested your app with an AdHoc provisioning profile prior to releasing it to the app store. The AdHoc profile works with the production push environment.
EDIT :
Some quotes regarding device tokens :
From the Local and Push Notification Programming Guide :
Take note that the device token in the production environment and the
device token in the development (sandbox) environment are not the same
value.
From Technical Note TN2265 :
Handling Malformed Notifications
The simple binary interface drops the connection if the push service
receives a notification that is incorrect in some way. Your provider
may see this as an EPIPE or broken pipe error in response to sending a
notification. On the other hand, the enhanced binary interface will
send an error response with more detailed information about what was
wrong with the notification before dropping the connection. Be sure
your provider catches and handles these conditions properly.
The most common problem is an invalid device token. If the token came
from the sandbox environment, such as when you are testing a
development build in house, you can't send it to the production push
service. Each push environment will issue a different token for the
same device or computer. If you do send a device token to the wrong
environment, the push service will see that as an invalid token and
discard the notification.
Finally, this article has a good explanation of how sending multiple notifications to Apple when some of the notifications are invalid (the most common cause being invalid device tokens), can cause some of the valid notifications not to arrive as well.

iPhone doesn't receive MDM Push notification sent by mdm server

Followed the steps mentioned here and Softhinker. Created the certificates and configuration profiles as mentioned. When the configuration profile is installed in the device, sends the Authenticate, Push Magic, and Token update to the mdm server. Till that point it is fine. But when the server tries to send a mdm push notification to the device with the mdm key and pushmagic, it is not received by the iPhone. At the server end, the push is sent successfully based on the console logs there. There is nothing to see in the console of iPhone. It doesn't show anything.
Some inputs regarding this would be helpful.
I followed the same steps as in Softhinker using openssl commands to generate the appropriate certificates. Used them on both the server (mdm server) and the client (iPhone). When the mobile config profile is installed, the server gets the details. And when the server sends the mdm push with the mdm environment to ask the device to poll for commands, that particular mdm push notification did not reach the device, how ever it shows as sent at server. Checked the mobileConfig profile created and the settings of it. Previously the mdm payload settings are as development environment. Changed it to production and tried again. Now all of it works. You might check with the production environment once, if that helps.
I've created a simple MDM platform that you can use for testing MDM commands.
It handles all the provisioning so you don't have to worry about OpenSSL.
It's called TestMDM - (http://www.testmdmapp.com)

Not Receiving Push Notifications

previously i had configured my app id for development push notifications it was working fine.
But now i have changed my appid and i have followed the same procedure as stated in the apple docs and i have put newly generated .p12 file on the server side but i am not getting the push to my device now.
i have a doubt for an apple id i generate both development and production ssl certificates and in programme portal both environments shows green balls.
i have created development provision profile after doing as said above. in the sever side do i need to point to production ssl or development ssl for testing.
can anybody have any idea about this
It depends which server are you contacting.
If you are testing on the development side, you have to send requests to the sandbox (gateway.sandbox.push.apple.com) using the appropriate SSL certificate and the appropriated Device Token.
If you are on production/release mode, you have to use the correspondent info.
Another thing that you have to keep in mind is that, for each certificate you have to register your device for push notifications, and if you change the provisioning profile, you have to do everything again, because the Device Token will be different.
Cheers,
VFN
Make sure that the device which you are testing doesn't have both the development profile and the distribution profile. Only distribution (adhoc) profile must be there.