我想知道我是否可以通过 Firebase 向用户发送多个推送通知,然后在用户在设备上看到它们之前拦截它们并允许我的应用有选择地允许通知。
这可能吗?
如果可以,我需要使用哪种方法? (来自 react-native-firebase
或 iOS
)
最佳答案
您可以尝试使用 UNNotificationServiceExtension
(iOS 10
可用)。您需要为您的项目添加一个扩展(example how to add)。
在您的扩展中实现方法 - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent *contentToDeliver))contentHandler;
之后。
它会在通知显示给用户之前调用,您可以尝试执行一些操作(例如:将一些数据保存到本地)。
请注意它仅适用于 iOS 10 rich notifications
( how to implement it with Firebase )。
附言希望对您有所帮助!
编辑:
Override this method and use it to modify the UNNotificationContent object that was delivered with the notification.
更新:
您可以尝试从服务器发送静默推送通知,检查它并创建本地通知以在需要时显示给用户。
关于ios - 有没有办法阻止用户在从 Firebase 发送后接收推送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44445715/