I'm trying to get push notifications to my iOS app using PushKit, but I never get a callback when registering for the notifications.
I actually DID both register ok and received notification earlier, but I must have managed to screw something up or gotten blacklisted by Apple.
I can still send the notifications fine (to sandbox apps), but I never get the notifications and I assume this has to do with the missing callback when registering in the app. Sending to production renders an "INVALID TOKEN" error which I assume is fine as the app isn't in the app store.
Any ideas on what's going on here ? Please ask for more info if I missed something.
gist with AppDelegate/settings/console output
I had the same issue. As #sugarngp mentioned in his comment above, my issue is that my PKPushRegistry object was getting deallocated. Once I made it an instance variable of my AppDelegate it fixed the issue.
Related
I've added Push Notification to my IONIC App using this tutorial: Using Push Notifications with Firebase in an Ionic + Angular App.
For Android all works fine, but on IOS notifications are not delivered. In my Firebase console there is an information that notification was sent, but nothing appeared on my IPhone. The app is installed by TestFlight (Internal Tests).
Questions would be:
How can debug or somehow detect where might be the problem?
If there is no way to check it, maybe there is a list of common problems with that?
Check if iOS push notifications permissions are enabled
Check to see if you receive a push notifications token when you run your app (it doesn't work on simulator, must be real device)
Register push notifications key on your apple developer account and add the key to your firebase app.
Push notifications on iOS is a bit tricky. This tutorial helped me: https://devdactic.com/push-notifications-ionic-capacitor/
Check on the client that it sends a push token to the server.
Check on the server if any errors are reported when pushes are sent to apple.
Check in the console logs whether and pushes appear on your client device.
Check in the app if any push notifications are received.
In addition to following the advice already listed and assuming that you have followed the linked tutorial in detail, what helped me to understand the problems related to my experience with push notifications is to check the validity of the token received from the
// On success, we should be able to receive notifications
PushNotifications.addListener('registration',
(token: PushNotificationToken) => {
alert('Push registration success, token: ' + token.value);
}
);
is to contact this link https://iid.googleapis.com/iid/info/{{Token}}?details=true by entering your received token. If the response contains an error your configuration is incorrect and the error should be found in the changes applied to AppDelegate.swift. Furthermore, I noticed that not always the listener to capture the token does not always activate after a registration and I had to insert in my app also the #capacitor-community/fcmplugin that offers the method
FCM.getToken ()
.then ((r) => alert (`Token $ {r.token}`))
.catch ((err) => console.log (err));
which always returns the token according to my tests, this solution has been applied only for iOS, moreover this plugin also allows you to manage topics efficiently. It's definitely not a clean solution but for me it solved a problem I've been struggling with for days. The last advice I can give you is to pay attention to the activation and deactivation of the listners and to try to use setTimeout () to understand if your failure to work derives from an incorrect initialization of the resources and if these must be moved to the app states where the resources required by the various methods are available.
I am currently trying to send push notifications from a device to another but the problem is when I send a notification, I get the error "InvalidApnsCredential" and "Not registered", whereas my certificates are valid because I succeeded in receiving push notifications from Firebase Cloud Messaging.
In fact, this kind of funny because it was working yesterday and today it's not. So, I re-uploaded the appropriate certificates but I keep on getting this error "InvalidApnsCredential".
I don't provide any code, you can still ask it to me if necessary but I feel like this error has nothing to know with my code.
I would be glad to know if someone has ever experienced that before and know how to fix this.
It seems to be a global issue of firebase.
During the latest 3 hours this issue has been reported several times.
Please check.
https://twitter.com/ios_overflow/status/1156946303466844165?s=20
Update...before I ever posted
I actually discovered the solution before I posted this but thought I'd post it anyway in hopes of saving someone else's time.
As a last resort I tried deleting the APNs Authentication Key and reverting back to the certificate for the application in Firebase Cloud Messaging project settings. That fixed it. Below is the message I'd intended to post.
I'm attempting to push notifications to subscribers of a specific topic using Firebase FCM. According to the Cloud Messaging console the notifications are being sent but they're never received by a device subscribed to the topic. I'm also not receiving test messages sent via the console.
I've confirmed the following:
APNS is properly configured for my project. I was able to receive a
notification on a device using a testing site
(https://www.apnstester.com/apns/)
The topic is being subscribed to or at least subscribeToTopic doesn't
return an error.
I'm receiving a remote instance ID token.
I'm receiving an APNS device token
I've also tried:
Enabling and disabling swizzling (and yes, when it's disabled I'm
setting the APNS token)
Deleting and reloading my APNs Authentication Key
Updating the Firebase framework
Removing and re-adding the GoogleService-Info.plist
I should point out this is old app (hence the Objective-C swizzling) and notifications worked fine in the past. Any suggestions or advice?
My code is in Objective-C
Firebase side
App created
General settings --> done
APNs Auth Key --> done
Apple developer account side
App ID --> done
Dev and Distribution certificates --> done
Dev and Distribution profiles --> done
App side
My AppDelegate calls registerForRemoteNotifications without any error and the method "didReceiveRegistrationToken" is able to return a string like in the following: NSLog(#"Remote instance ID token: %#", result.token);
First item confirms that my app is able to reach Firebase Server and APNs because a TOKEN returns always!
I have implemented all functions didReceiveRemoteNotification both if I am receiving a notification message while the app is in the background and if it isn't.
GoogleService-Info.plist --> moved inside my project
PROBLEM
The problem is my app is not able to receive any notification I am going to send by using the firebase console. didReceiveRemoteNotification never called!
I have read all your feedback on other questions but I didn't solve my problem.
UPDATE #1
Thank you iDev750 for your answer!
My problem is I do not receive notifications on my app when I send them from the firebase console or directly from my backend. In my opinion if I do not receive a notification it is impossible that didReceiveRemoteNotification is called, are you agree with me?
Anyway, as you said, I sent a push message directly to my token/device and the result is in the following:
{"multicast_id":6185922XXX,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1543141675131005%YYYY"}]}
So, it is sure the message has been sent, otherwise the output should be something like The request's Authentication (Server-) Key contained an invalid or malformed FCM-Token (a.k.a. IID-Token).
I hope I was clear with this my second message. Do you have any idea to help me?
Thank you so much!
Here you said two points in your question.
Notification is not receiving in your app.
didReceiveRemoteNotification never called.
First, which is your problem? becasue both are different issue.
You can do one thing that just install your app in iPhone and paste your device token on Firebase console and send test notification on that device. Just forget about "didReceiveRemoteNotification" method that calling or not.
Now, if you are getting notifications but didReceiveRemoteNotification is not calling then check my answer:
https://stackoverflow.com/a/53460880/1673192
If notification is receiving on the device, might be some other issue like -
Is push notification enable for your AppId created on AppStore?
Is push notification enable in your app -> Targets -> Capabilities -> Push Notifications
Check these points and let me know still you have any issue.
I face the following weird problem. I have a setup for notifications using Azure NotificationHub and Xamarin to develop an iOS app. It works fine with the following exception. Some times some notifications sent from my backend server (C# Visual Studio Windows Form Application) cause the iPhone to flash, I hear the notification sound, no notification is shown and older notifications of my app are removed from the list. Any idea what might be causing this?
Thanks
I see that you write:
I hear the notification sound, no notification is shown and older notifications of my app are removed from the list.
If you hear the notification sound, that means that the neither the APNS nor the Azure Notification Hub is the problem, because you are actually receiving the notification on the device.
No notification is shown.
1.This means that either the implementation of your code is deciding to actually receive the notification and do nothing with it. Check t Receiving Push Notifications while in background
This could also mean that in settings you disabled all the notification balloons, alerts and other properties. Make sure your app has actually the proper settings to work with notifications. (Believe me, it happens) https://support.apple.com/en-us/HT201925
Older notifications of my app are removed from the list. First of all I do not understand how do you have notifications on the list (did you actually received notifications somehow?). In any case, the notifications are removed by code when you enter your app. Please review this question (iOS application: how to clear notifications?)
Please mark my answer correct if it helped you, if not. Please provide more code of your implementation so we can provide you a better answer.
Best Regards.