-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DOC NEEDED] - How to implement a custom notifications delegate on iOS? #1631
Comments
By the way, I have found out another issue related to the iOS notifications. The application is not notified by any Capacitor push notification callback when a notification is received while the application is in background. In addition, if the notification is "content-available" the application is not notified either in background or foreground. In order to support this iOS feature it should be necessary to implement this method of AppDelegate:
|
Hey @rpanadero, I have found this issue too. My iOS app is not receiving FCM push notifications. It does when I send the test message to the entire app, but not individual messages, which are working on Android. How do we implement your code you mentioned above? |
This is an issue for me too. Any plan on supporting custom UNUserNotificationCenterDelegate implementations anytime soon? Thanks! |
how are you doing the custom If you do it in the load method of a custom plugin it should be called after the |
I'm working on a plugin for the Salesforce MarketingCloudSDK (https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/get-started/apple.html). As per the instructions of this SDK (and also the Apple iOS documentation*), the UNUserNotificationCenterDelegate must be set in "application(_:didFinishLaunchingWithOptions:)". The problem is, that CAPUNUserNotificationCenterDelegate sets itself as the delegate after this. So there is no way for me to set my custom delegate at the right point without it being "overwritten" by Capacitor afterwards. * See the "Important" box here: https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate |
Hi @jcesarmobile, I tried it with custom code and it happens what @philet says. Capacitor registers his delegate after mine it is set, so we could say that yours have more priority. My problem was the same as @philet describes above. My notifications SDK required that my application called a specific method on Finally, as I could do that easily, I decided to just use the Capacitor Core for push notifications handling and notify the notifications SDK from hybrid side by calling a plugin method. Maybe, it is not the best approach, but I guess that it is the easiest way to avoid having the same problem we had on Cordova when we had multiple notifications plugins which overrided the same delegate methods by doing swizzling. That experience on Cordova was awful because I was always frightened of breaking something. If you let me suggest something, I think that another possible approach could be to implement the Like that, you could catch this event in On the other hand, I remember you that I also realized that you are not implementing in
So, if I receive a silent push notification my application is not notified and I cannot handle it. And the same happens, if the push notification is received in background although it is a non-silent one. Feel free to tell me anything about my suggestions. Thanks in advance |
I've sent a PR to not override the UNUserNotificationCenterDelegate if present, so people can use custom delegates if they want. I don't like the idea of moving the whole I didn't have any problem receiving regular push when the app is in background or closed, but silent pushes are not supported at the moment, we will add the |
Just did some testing and by doing this with a custom
From custom plugins is even easier as they already have the bridge object and can skip the |
Thank you very much @jcesarmobile |
@jcesarmobile does your solution work for Capacitor v3? |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out. |
Description of the problem:
First of all, I'm sorry if this shouldn't be reported as bug report, but I need help with this matter as soon as possible.
The problem that I'm facing is related to having a custom notifications delegate on iOS. I have been having a look at Capacitor core and I have seen that there is a delegate set for
UNUserNotificationCenter
. However, this delegate implementation doesn't fit me because my app business requirements need another one. How could I override this implementation? If I try to register another delegate in my application AppDelegate, which is versioned, it doesn't work because Capacitor core registers its delegate later.On the other hand, I does be able to do what I want on Android by registering a custom FirebaseMessagingService in AndroidManifest.xml. In addition, I can even call Capacitor Push Notifications plugin to avoid breaking its implementation.
Affected platform
OS of the development machine
Other information:
Capacitor version: 1.0
node version: 11.4.0
npm version: 6.5.0
CocoaPods version: 1.7.1
The text was updated successfully, but these errors were encountered: