Skip to content

Instantly share code, notes, and snippets.

@3257
Last active March 1, 2018 10:20
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 3257/75d198a3aaca6ebd1e5924fab366a3d8 to your computer and use it in GitHub Desktop.
Save 3257/75d198a3aaca6ebd1e5924fab366a3d8 to your computer and use it in GitHub Desktop.
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// 1. Access the payload notification content once received
if let apnsData = response.notification.request.content.userInfo["aps"] as? [String: Any] {
// 2. Get the imaginary storeID from the payload
if let storeID = apnsData["storeID"] as? Int,
// 3. When a notification is received and your app opens up you would generally get the initial View Controller
// You can then access the InitialViewController and parse the it, and you can then access its functions.
let initialVC = self.window?.visibleViewController as? InitialViewController {
// 4. Using the initialVC function for getting a StoreViewController by a given storeID.
// The getStoreViewController could simply perform a segue programatically and navigate from the InitialViewController to the StoreViewController
initialVC.getStoreViewController(by: storeID)
}
completionHandler()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment