Skip to content

Instantly share code, notes, and snippets.

@orospakr
Last active June 13, 2019 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orospakr/9ac4fe6c8f9c1c905114a7c3dfc3008a to your computer and use it in GitHub Desktop.
Save orospakr/9ac4fe6c8f9c1c905114a7c3dfc3008a to your computer and use it in GitHub Desktop.
Example of how to open a Rover Notification manually.
// NOTE: a future update is going to render this code unnecessary.
let notification = // get a reference to the Rover Notification using your own table data source.
// Resolve various Rover subsystems from the SDK that you will need to do the below logic.
// (Change `RoverCampaigns` to `Rover` if you are still targetting 2.x)
let notificationStore = RoverCampaigns.shared!.resolve(NotificationStore.self)!
let router = RoverCampaigns.shared!.resolve(Router.self)!
let dispatcher = RoverCampaigns.shared!.resolve(Dispatcher.self)!
let eventQueue = RoverCampaigns.shared!.resolve(EventQueue.self)!
if !notification.isRead {
// 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.
notificationStore.markNotificationRead(notification.id)
}
// now we have to handle the different behaviours for different kinds of notification:
switch notification.tapBehavior {
case .openApp:
break
case .openURL(let url):
if let action = router.action(for: url) as? PresentViewAction {
action.viewControllerToPresent.transitioningDelegate = self
dispatcher.dispatch(action, completionHandler: nil)
} else {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
case .presentWebsite(let url):
if let action = RoverCampaigns.shared!.resolve(Action.self, name: "presentWebsite", arguments: url) {
if let presentViewAction = action as? PresentViewAction {
presentViewAction.viewControllerToPresent.transitioningDelegate = self
}
dispatcher.dispatch(action, completionHandler: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment