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 ?? "-") }
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
Post a Comment