[DOC NEEDED] - How to implement a custom notifications delegate on iOS?
See original GitHub issueDescription 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.
public class MyAppFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(String newToken) {
super.onNewToken(newToken);
PushNotifications.onNewToken(newToken);
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
PushNotifications.sendRemoteMessage(remoteMessage);
// I can do whatever I want
}
}
<service android:name="com.demo.myapp.services.MyAppFirebaseMessagingService" android:stopWithTask="false">
<intent-filter android:priority="9999">
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
Affected platform
- Android
- iOS
- electron
- web
OS of the development machine
- Windows
- macOS
- linux
Other information:
Capacitor version: 1.0
node version: 11.4.0
npm version: 6.5.0
CocoaPods version: 1.7.1
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (3 by maintainers)
Just did some testing and by doing this with a custom
UNUserNotificationCenterDelegate
inAppDelegate
the Capacitor one keeps working as expected.From custom plugins is even easier as they already have the bridge object and can skip the
let capVC = self.window?.rootViewController as? CAPBridgeViewController
part.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: