Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. // NOTE: a future update is going to render this code unnecessary.
  2.  
  3.  
  4. let notification = // get a reference to the Rover Notification using your own table data source.
  5.  
  6. // Resolve various Rover subsystems from the SDK that you will need to do the below logic.
  7. // (Change `RoverCampaigns` to `Rover` if you are still targetting 2.x)
  8. let notificationStore = RoverCampaigns.shared!.resolve(NotificationStore.self)!
  9. let router = RoverCampaigns.shared!.resolve(Router.self)!
  10. let dispatcher = RoverCampaigns.shared!.resolve(Dispatcher.self)!
  11. let eventQueue = RoverCampaigns.shared!.resolve(EventQueue.self)!
  12.  
  13. if !notification.isRead {
  14. // ask Rover to mark the notification as read. Note, if you are showing the unread state in the row, yu may want to book-end this call in `tableView.beginUpdates/endUpdates`, etc.
  15. notificationStore.markNotificationRead(notification.id)
  16. }
  17.  
  18. // now we have to handle the different behaviours for different kinds of notification:
  19. switch notification.tapBehavior {
  20. case .openApp:
  21. break
  22. case .openURL(let url):
  23. if let action = router.action(for: url) as? PresentViewAction {
  24. action.viewControllerToPresent.transitioningDelegate = self
  25. dispatcher.dispatch(action, completionHandler: nil)
  26. } else {
  27. UIApplication.shared.open(url, options: [:], completionHandler: nil)
  28. }
  29. case .presentWebsite(let url):
  30. if let action = RoverCampaigns.shared!.resolve(Action.self, name: "presentWebsite", arguments: url) {
  31. if let presentViewAction = action as? PresentViewAction {
  32. presentViewAction.viewControllerToPresent.transitioningDelegate = self
  33. }
  34.  
  35. dispatcher.dispatch(action, completionHandler: nil)
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement