如何控制推送通知中按钮的功能?

发布于 2024-12-02 14:52:00 字数 204 浏览 1 评论 0原文

我能够向 iOS 设备发送推送通知。通知上有一个“关闭”按钮和一个“查看”按钮。当用户点击“查看”按钮时,应用程序将打开根视图控制器。该应用程序内有一个新闻部分。假设该通知是为了提醒用户有新的新闻报道可供他们查看。如果他们点击“查看”,将显示根视图控制器,而不是新闻视图控制器。我将如何打开新闻视图控制器? Facebook 经常使用这个。这是否需要在服务器或应用程序内进行更改?感谢您的帮助!

I'm able to send push notifications to iOS devices. There is a "Close" button on the notification and a "View" button. When the user hits the "View" button the app opens up to the root view controller. Within the app there is a news section. Let's say the notification is to alert the user that there is a new news story for them to see. If they hit "View", the root view controller will show, instead of the news view controller. How would I go about opening the news view controller? Facebook uses this a lot. Would this be something to change on the server or within the app? Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森末i 2024-12-09 14:52:00

对于通知中的 iOS 8+ 操作按钮:

对于本地通知,当按下通知上的按钮(锁定屏幕或横幅)时,appDelegate 会调用此方法:

- (void)application:(UIApplication *)application
   handleActionWithIdentifier:(NSString *)identifier
         forLocalNotification:(UILocalNotification *)notification
            completionHandler:(void (^)())completionHandler

对于 推送通知,当按下通知上的按钮(锁定屏幕或横幅)时,appDelegate 会调用此方法:

- (void)application:(UIApplication *)application
   handleActionWithIdentifier:(NSString *)identifier
        forRemoteNotification:(NSDictionary *)userInfo
            completionHandler:(void (^)())completionHandler

For iOS 8+ action button in notifications:

For local notification, appDelegate calls this method when a button on the notification (lock screen or banner) is pressed:

- (void)application:(UIApplication *)application
   handleActionWithIdentifier:(NSString *)identifier
         forLocalNotification:(UILocalNotification *)notification
            completionHandler:(void (^)())completionHandler

For push notification, appDelegate calls this method when a button on the notification (lock screen or banner) is pressed:

- (void)application:(UIApplication *)application
   handleActionWithIdentifier:(NSString *)identifier
        forRemoteNotification:(NSDictionary *)userInfo
            completionHandler:(void (^)())completionHandler
北风几吹夏 2024-12-09 14:52:00

您必须检查应用程序委托中的启动选项:

application:didFinishLaunchingWithOptions

您可以在其中获取推送通知的有效负载字典。

You have to check the launch options in your application delegate:

application:didFinishLaunchingWithOptions

There you can obtain the payload dictionary of the push notification.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文