ios - 如何处理点击推送通知 ios

标签 ios push-notification

我设法收到推送通知,但我不知道如何处理到达应用程序的推送通知上的点击,我想根据通知类型告诉应用程序何时点击转到特定事件,不只是打开应用程序(默认行为)

我知道我可以接收

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{

    NSLog(@"Here I should Recive The notification .... ") ;
    //call the commented functions .....
}

在这个函数中,但是当我实现它时,通知不会出现,只是在这个函数中做些什么

最佳答案

对于在 2022 年遇到此问题的任何人,这里有一个可行的解决方案。连接推送通知服务后,您需要在 AppDelegate 中实现 didReceive 函数,然后获取通知内容:

func userNotificationCenter(_ center: UNUserNotificationCenter,
                            didReceive response: UNNotificationResponse,
                            withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content.userInfo
    let title = response.notification.request.content.title
    let message = response.notification.request.content.body
    userDefaultsManager.savePushNotificationData(pushNotificationData: ["title" : title, "message" : message])
}

请注意,如果您需要在推送本身中获取自定义数据,它将存储在 userInfo 中。 你可以这样得到它:

func userNotificationCenter(_ center: UNUserNotificationCenter,
                        didReceive response: UNNotificationResponse,
                        withCompletionHandler completionHandler: @escaping () -> Void) {
     let userInfo = response.notification.request.content.userInfo
     let url = userInfo["url"]
}

关于ios - 如何处理点击推送通知 ios,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22780275/

相关文章:

ios - 使用 Swift 4 将 Pdf、Docx 和图像文件上传到服务器

ios - 如何从 ABAddressBookRegisterExternalChangeCallback 获取更新的联系人列表?

ios - 如何在 ObjC、iOS 中解析数据时内联显示数据

php - 推送通知未在多台设备上接收 - 仅在一台设备上推送

android - 带操作按钮的 Cordova Android 推送通知

android - 通知不是大图像和图标不显示

ios - 标签栏显示警报消息

iphone - 当 objective-c 中出现推送通知时,如何在没有用户交互的情况下将 iphone 应用程序从后台带到前台?

android - 每次应用程序启动时在 GCM 上注册设备是正确的方法吗?

html - UIWeb View : css ignored