Independent Watchkitapp APNS push notification successful send but notification does not receive in Apple Watch - swift

I have created an independent watchkitapp in XCode, installed in apple watch and successfully sent push notification without errors from Pusher app (also in node-apn) but the notification does not arrive in app. (Tried another app for iOS and remote push notification successfully received in iOS app)
These are the steps i took
In my watchkitapp I did WKExtension.shared().registerForRemoteNotifications() and took the device token
UNUserNotificationCenter.current().requestAuthorization and allowed push notification on apple watch. ofcourse I set UNUserNotificationCenter.current().delegate to the InterfaceController (I tried Local Notification and local notifications display normally on the watch)
On XCode watchkitapp.watchkitextension I added Push Notification on capabilities
In Apple Developer page I created app id mirroring the watchkitapp bundle (not the watchkitextension one). In my case apple automatically created App Id in the server but I removed and recreated it to make sure
Checked the Apple Push Notification service and generated Development SSL Cert
Downloaded the Development SSL Cert and installed in keychain
Opened the Pusher app and selected the installed Development SSL Cert from the list. Ran the apple watch app and obtained the Token Id... sent the payload and it says the payload is sent
Tried to restart mac, iphone, apple watch, unpairing apple watch, reinstalling app but the result is the same... push is sent but does not receive in apple watch
anybody can help me how can I fix this?

Finally, I got this successfully. I use node-apn to send from server.
Here are the worth noticing things:
create app id of the watchkitapp bundle in Apple Developer page
install the latest version of: node-apn,
"dependencies": {
"apn": "git+https://github.com/node-apn/node-apn.git#3.0.0",
[...]
}
should set apns-push-type
notification.pushType
(Required when delivering notifications to devices running iOS 13 and later, or watchOS 6 and later. Ignored on earlier system versions.)
The type of the notification. The value of this header is alert or background. Specify alert when the delivery of your notification displays an alert, plays a sound, or badges your app's icon. Specify background for silent notifications that do not interact with the user.
The value of this header must accurately reflect the contents of your notification's payload. If there is a mismatch, or if the header is missing on required systems, APNs may delay the delivery of the notification or drop it altogether.

Related

FCM push notifications are not working on TestFlight after some time

I have uploaded a build to Testflight and started testing the push notifications which were developed using Firebase. I used distribution certificate for TestFlight build and also set the setApnsToken to prod. The entitlement file is generated by enabling push notifications and background mode with Remote Notification.
While testing, i have received 23 notifications and then it suddenly stopped receiving notifications.
I checked the device token n it's registered. The device token is same for both i.e. for successfully delivered notifications and failed to receive notifications.
I tried for 2 days but the same thing is happening.
Note.-
I am using the single device to test.
I am sending device token at the time of login by using InstanceID.
The device token is cleared on user logout at the server side.
The device token is always registered at the time of login (checked the entries at server side).
Any help is very much appreciated. THANKS IN ADVANCE

Sending IOS notifications from Firebase (or another platform) to specific terminales

We are currently able to send notifications to specific Android devices through Firebase and I am trying to do the same to IOS devices.
We use POD and have installed
pod 'Firebase/Core'
pod ‘Firebase/Messaging'
We've created an account with Firebase.
I have added the functions that correspond to AppDelegate.swift. After executing the app, I can send notifications from Firebase to all iPhones... but no specific ones.
In production, I have the following
FIRInstanceID.instanceID().setAPNSToken(deviceToken, tape: FIRInstanceIDAPNSTokenType.prod)
Up to here, all good .. but when I try to get the token from a user and then send a notification only to that device... the notification does not arrive
The token is generated without any problems.
if let refreshedToken = FIRInstanceID.instanceID().token() {
print(“InstanceID token: \(refreshedToken)”)
}
From firebase The notification is sent and does not show errors.. but the notification never arrives to the actual device.
Can this be done with Firebase?
Is there any other service that would allow me to do this?
UPDATE
I send message for console
click open image
On Android, Firebase has the luxury of using GCM directly. For Apple, FCM messages need to be sent to Apple Push Notifications.
Make sure you have setup the backend by downloading your APN Key and uploading to your Firebase console:
Download: https://firebase.google.com/docs/cloud-messaging/ios/certs
Upload: Open your Firebase console, click on the gear icon in the upper left, click on Project settings and then the Cloud Messaging Tab. Upload your APN key there.
You should be able to grab the FCM device ID from the debug output console when Firebase starts up (when running the app in debug mode).
You need to update your Firebase pod and add code from this answer to your iOS Application-
Working Firebase Messaging Code for iOS App

Push notification data when app is not running?

When the app is not running and user receives, say 5 push notifications, are those push notifications saved somewhere? Or is that data gone? I need to access all 5 push notifications when the app runs the next time.
To clarify, I already understand that you can access the push notification that caused the app to run. What I'm asking is to get all push notifications since the app got terminated.
The APNS service will only retain the most recent pushed message to a device - assuming there is still at least one other app installed AND the user allows push notifications for it, then this one stored message will be delivered the next time the user has an Internet connection.
For better information on the quality of service that Apple has implemented for the APNS service, see my other answer here:
Clarification on Apple APNS

iPhone Push Notification Reliablity

How reliable do you find push notification on the iPhone to be? Does it improve when moving from the sandbox to production server?
I am testing (with the sandbox of course) and have found that notifications are often delayed or not received at all. I am not talking about sending multiple messages and only the last one arriving, as the documentation indicates, but any notification never showing up.
Also, I noticed that if I send a notification with an alert, and then send one with just a badge number, that the second notification will close the alert even after it's already opened. Does this happen between apps as well? For instance, if I send an alert for my app, and then the Facebook app sends a badge, will the Facebook badge close my alert window?
I have no development experience with iPhone apps, but I do know that if you have an unofficial unlocked phone (by using pwnage tool/blackrain etc) then the PUSH notifications might NEVER go through. In fact, it does go through, but to another user's iPhone.
This is because when an iPhone is unofficially network unlocked, it uses the Unique ID of some random individual's iPhone, which causes Push notifications to arrive on either phone (and yes, sometimes also on the unlocked phone it was intended for, but usually not)
Not sure if this is the case with you though, but AFAIK the service is pretty reliable if you follow Apple's rules. :)
The push notification seams better on production. You can always test it using ad-hoc distrbution which uses the production chanel to send the notifications.
I can confirm that production push notifications using
Production Push Notification Certificate
Adhoc Distribution Mobile Provisioning
TestFlight deployment
Production APNS server
works well, no need to publish your app to test production notifications
Production push notifications are not always received. If notifications are machine gunned 1 second apart the first one is received and the rest are not sent, thats my experience.
Where as on a windows phone, they are all received using the windows notification service.

Testing Apple Push Notifications Feedback - no items received

How to test feedback.sandbox.push.apple.com? Everything goes right, but I receive empty list.
How to make it consider the device token as inactive?
I installed the application to iPhone using Xcode, received some push notifications, then removed it from iPhone and send some more notifications. But even on the next day feedback.sandbox.push.apple.com returns just empty set.
Issues with Using the Feedback Service
If you remove your app from your device and then send a push notification to it, you would expect to have the device token rejected, and the invalidated device token should appear on the feedback service. However, if this was the last push-enabled app on the device, it will not show up in the feedback service. This is because deleting the last app tears down the persistent connection to the push service before the notice of the deletion can be sent.
You can work around this by leaving at least one push-enabled app on the device in order to keep the persistent connection up. Just install any free push-enabled app from the App Store and you should then be able to delete your app and see it appear in the feedback service.
source:
http://developer.apple.com/library/ios/technotes/tn2010/tn2265.html#TNTAG34
I far as I found, Apple push notification feedback service doesn't work properly on sandbox mode. You should try it on ad-hoc or production mode.