我可以选择在Android中接收推送通知,但在IOS上我找不到同等的方法。
在android中,我可以覆盖:
@Override
public void remoteNotificationReceived(Context context, OSNotificationReceivedEvent notificationReceivedEvent) {
OSNotification notification = notificationReceivedEvent.getNotification();
notificationReceivedEvent.complete(notification);
<-- I can do something with the notification data here.
}
我如何在iOS中做到这一点?
如果有什么不同的话,我用的是onesignal。
在iOS上,用户必须选择加入才能接收通知。我建议遵循整个过程的教程。这是Ray Wenderlich的教程。
假设您已经完成了所有的设置,那么您要查找的代码就在UNUserNotificationCenterDelegate中。具体而言,
@available(iOS 10.0, *)
optional func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
@available(iOS 10.0, *)
optional func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async
这取决于您想要异步还是闭包。