George Parkinson
George Parkinson

Reputation: 19

Retrieve data and open view controller from FCM notification data IOS

When I send this data to my android device it works correctly and an activity opens corresponding to the 'click_action'. I am also able to collect the data such as 'title' and 'price' and put them into strings.

However with iOS I can't figure out how to collect the data from the notification and then open a certain view controller when the notification is clicked.

Notification Data

Any help is much appreciated. Thanks a lot.

Upvotes: 1

Views: 414

Answers (1)

user9373173
user9373173

Reputation:

Using didReceiveRemoteNotification is the current way of handling touch events.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
if let userInfo = launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] {
  NSLog("[RemoteNotification] applicationState: \(applicationStateString) didFinishLaunchingWithOptions for iOS9: \(userInfo)")
  //TODO: Handle background notification
}
return true
  }

Notes: NO notification will appear on device’s notification center when receiving remote notification in active state. You may need to present your notification in your own way. If you need to present or push view controllers based on the content of notification. You need to save the content of notification and handle it until UIs are all ready.

Courtesy of FCM on Swift 3

Upvotes: 1

Related Questions