How to control what the buttons in push notificati

2019-02-28 19:35发布

问题:

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!

回答1:

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

application:didFinishLaunchingWithOptions

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



回答2:

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