ios - Swift 3 Get Notification Data -


i'm trying data out of notification in swift 3, using tutorial: developing push notifications ios 10 unfortunately following error:

private func getalert(notification: [nsobject:anyobject]) -> (string, string) {     let aps = notification["aps"] as? [string:anyobject]     let alert = aps["alert"] as? [string:anyobject]     let title = alert?["title"] as? string     let body = alert?["body"] as? string     return (title ?? "-", body ?? "-") } 

enter image description here

the issue notification declared dictionary keys of type nsobject. attempt access dictionary key of type string. string not nsobject. 1 solution cast string nsstring.

fixing presents error fixed on next line. code ends this:

private func getalert(notification: [nsobject:anyobject]) -> (string, string) {     let aps = notification["aps" nsstring] as? [string:anyobject]     let alert = aps?["alert"] as? [string:anyobject]     let title = alert?["title"] as? string     let body = alert?["body"] as? string     return (title ?? "-", body ?? "-") } 

having said of that, tutorial has lot of mistakes , uses wrong parameter types in many places. getalert method should not using nsobject. should string.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -