I've got a problem with the integration of Apple push notifications for Apple Wallet with my web service.
What works:
Endpoints (as described in https://developer.apple.com/library/content/documentation/PassKit/Reference/PassKit_WebService/WebService.html);
Passes are valid, they work with an iPhone, registering, manual update, unregistering, etc. seem to work, no errors from the logs of my server;
The response from "Getting the Latest Version of a Pass" endpoint has the "Last-Modified" header.
Then I update a pass on the server. When I try to send a push notification nothing happens.
I did some debug, APN Server (https://api.push.apple.com:443) returns code 200 with an empty body and non-empty "apns-id" header. This looks OK (https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html).
BUT! There are neither notifications nor an updated pass in Wallet on my iPhone.
When I do manual update, the pass updates and an update notification shows.
I cannot get what I did wrong...
P.S. I use https://github.com/mdigger/apns for making requests to the APNS.
When connecting to APNS for Wallet updates, you need to connect with the same Pass Type ID Certificate that was used to sign the pass.
See the section:
Your Server Sends a Push Notification When Something Changes
in the wallet documentation.
Your server sends the following pieces of information:
The pass type identifier (in the certificate)
The push token (in the communication to the Apple Push Notification service)
Related
I'm using "twilio_voice" for a flutter application for generating and receiving call from app to real number and vice versa.
When I'm trying to call to a real number from app it's working fine. But when i'm trying to receive call within the app, it's not working.
When I checked at Twilio console I found "Error 52134 Invalid APNs device token".
I have already created the VOIP certificate in Appstore console and also generated a Push Credential in Twilio console. The SID also used in the backend.
In my applog I also found "Successfully registered for VoIP push notifications." as a confirmation.
But still not working.
After your app has register for the push notification, you will need to create a binding with the Push Token to the Twilio server. For that you will need an intermediate server of your own(Can be a Node js/PHP/Python server application). First you will make a rest api request to your own server from the app. The server application will send a binding request to Twilio server. Once that is done, you will receive push notification every time there is an incoming call via didReceiveRemoteNotification() delegate in AppDelegate.
For the server application sample and Rest api sample for iOS app, follow this documentation from Twilio:
https://www.twilio.com/docs/notify/register-for-notifications-ios
Got the solution.
The issue was in the registering device. I was sending fcm token to the server for registering device. But after changing it device UUID, it worked.
Also point to be noted that, you will need a different SID from Twilio for development and Testflight. SID from Sandbox credentials won't work if you running app from TestFlight.
I'm currently implementing push notifications from our backend server to our app (macOS Catalina & iOS - same code base), using Apple Push Notifications & the token based way of authentication (generating JWT from keyId, teamId, ... & signing it with the private key generated in the Apple developer console) to send pushes to APN service.
The problem I am facing is that I can successfully send "alert" notifications (status 200, with header apns-push-type: alert) and receive them on my iOS and MacOS device (the push notifications appear successfully in production and sandbox mode) but for some reason, "silent" pushes (with header apns-push-type: background) are only received on my iOS device (iPhone), but not on my Mac (didReceiveRemoteNotification(...) in AppDelegate is never called).
What I have done so far:
Made sure APN request header is correctly configured for silent push: apns-push-type: background
Made sure to have the correct APN topic header: apns-topic: my.bundle.id (this is different for sandbox/production)
Added the "semi-required" priority header: apns-priority: 5 (only when delivering background pushes)
Verified that the created JWT is valid and used in the APN auth header: authorization: mytoken (this must be the case, otherwise APN service would not respond with status 200)
Confirmed that my application has the correct entitlements & capabilities defined in Xcode (my reasoning: this must be the case, otherwise 'alert' push notifications would also not work)
Double checked that push notifications for the Mac app are allowed/enabled (checked system settings)
Made sure the device token im sending the push to is actually from the device intended to receive the push (e.g. my MacBook)
Checked that the private key I'm using to sign the JWT has the APN capability
Tested while the Mac app is running but not in focus & also when in focus
The APNs requests I am performing to send the push are:
Sandbox: POST https://api.sandbox.push.apple.com/3/device/{deviceToken}
Production: POST https://api.push.apple.com/3/device/{deviceToken}
The payload (JSON) I'm sending to APN service in the request body looks as follows:
{
"aps": {
"content-available": 1 # defines push as "silent"
},
"data": { #some key-value pairs here }
}
In any case (both production & sandbox, both with the device token of iOS and macOS), my request to APN returns with a status code 200. My MacBook is running Catalina 10.15.3. What am I possibly doing wrong here or is that something that is simply not supported for Catalyst apps?
Wow doozy question. I'm reasonably familiar with APNs headaches but something popped out at me from the latest docs:
Additionally, the notification’s POST request should contain the
apns-push-type header field with a value of background, and the
apns-priority field with a value of 5. The APNs server requires the
apns-push-type field when sending push notifications to Apple Watch,
and recommends it for all platforms. For more information, see Create
and Send a POST Request to APNs.
Does the priority 5 thing make a difference?
Also my usually attempt to fix these problems is to test in an archive as opposed to an Xcode build. AFAIK the prod push server can only send to App Store, ad-hoc, enterprise, or testflight builds, so if you're just building from Xcode I don't think you'd get any push notifications with production apns.
I am trying to determine what I need to do with respect to the combination of APNS endpoint (e.g., development or production), Xcode, and Apple Push certificates in order to test push notifications while in development. I feel like I've tried every possible combination, but I must be missing something ...
Background
When using Apple's HTTP/2 APNS endpoints from my "dispatch" server, my app/device does not receive pushes, and I receive a BadDeviceToken response from Apple.
Using the exact same .p12 certificate and deviceToken with the Pusher macOS testing app (which uses legacy APNS endpoints), the pushes successfully deliver.
To complicate this further ...
When using Apple's HTTP/2 APNS endpoints from my "dispatch" server for PassKit pushes, my pass/device does receive pushes.
So ...
Point #3 tells me that my "dispatch" server must be configured properly, because pushes to the Apple Wallet pass cause a response (e.g., I can see follow-on requests to my server's endpoints from the Wallet / the pass).
That said, Apple Wallet is a "Production" app. I suspect that, because my app (from Point #1) is non-production/development, something is different.
.
Question
Has anyone been able to successfully receive -- in Xcode -- push notifications sent to Apple's api.development.push.apple.com endpoint? Can you outline the steps you performed (which certificate from developers.apple.com, etc.)? Thank you!
You should be able to send development push from server:
You need to connect to api.development.push.apple.com:443 instead of api.push.apple.com:443. You can use production certificate for both.
Sending push to production server can not work with development builds - only with a build that is exported with AppStore configuration, but you can't debug those (at least not with Xcode)
If you need to check whether the production endpoint works, you can use testflight
Set development certificate from apple developer portal.
Use either production/test server for communicating with APNS.
Edit your target scheme as follows :
This will ensure that when push notification arrives, control will itself fall in the code. It might seem confusing. But here it is how it works :
- Install app on device and stop the Run process from Xcode.
- Place a breakpoint on didReceiveRemoteNotification.
- Send a push notification to device.
- Xcode will itself start the app and control will go to the above function.
I am using message chat service in my application by service request and response. But problem is that when sender sending message to receiver end receiver did'nt get any notification about the send message.
Just tell me what is the best option to respond the notification to the receiver.
Can it possible without using apple push notification service.
Adding my answers below if someone comes later with the exact same question.
If app is in foreground and user is doing live chatting you can use any of the lightweight messaging protocol(like MQTT/XMPP) to notify about new message. In this case better to put message as a payload itself for instant messaging.
For reference you can check out sample code here how to do it with MQTT.
But you should debug why your notification is not working. There are few checkpoints I can see:
1) Check your device tokenId you are storing on your application server.(In case of APNS it should be of 64 char length).
2) Check if push notification is enabled for you application in apple developer member center.
3) Check your SSL certificate used by your application server is proper. here is the simple step by step guide to get SSL cert.
https://blog.applozic.com/get-your-apple-push-ssl-certificate-abebf1edb338#.v7xu5cn0k
4) Make sure your code signing cert type is matching with apple push SSL certificate.Like if you are signing your code with developer certificate, apple push ssl cert should be of development one (not distribution).
Hope this might help others.
APNS is not for CHAT Use XMPP or MQTT. for both you will require a server side implementation.
For XMPP you can use use XMPPFramework. and for MQTT you can use Mosquito.
first you have to seen the all properties of the push notification like token id is right or not. is your appid enable the push notification service or not.
I wish to include in my registration message to our server, a flag as to which APNS server is being used. sandbox or production. I wish to do this so that my code can simply look up the device token and notification server from the table of devices, so that continuing development can coexist with live devices.
The application does, in development, register properly, linking a customer ID in our system to the token string from the phone.
However, this does not allow me to determine programatically from our server which push notification server to use.
I'm not sure if I have your question right, but as per Apple's doc Local and Push Notification Programming Guide: The Notification Payload
Providers can specify custom payload values outside the Apple-reserved
aps namespace.
So all you need to do is craft your custom payload to indicate which server the notification was pushed from, and read it when it gets to the App.