简体   繁体   English

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

[英]How to control what the buttons in push notifications do?

I'm able to send push notifications to iOS devices. 我可以将推送通知发送到iOS设备。 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. Facebook经常使用此功能。 Would this be something to change on the server or within the app? 是在服务器上还是在应用程序中更改某些内容? Thanks for your help! 谢谢你的帮助!

For iOS 8+ action button in notifications: 对于通知中的iOS 8+操作按钮:

For local notification , appDelegate calls this method when a button on the notification (lock screen or banner) is pressed: 对于本地通知 ,当按下通知上的按钮(锁定屏幕或横幅)时, appDelegate调用此方法:

- (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: 对于推送通知 ,当按下通知上的按钮(锁定屏幕或横幅)时, appDelegate调用此方法:

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

You have to check the launch options in your application delegate: 您必须在应用程序委托中检查启动选项:

application:didFinishLaunchingWithOptions

There you can obtain the payload dictionary of the push notification. 在那里,您可以获得推送通知的有效负载字典。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM