This is the following code but i am getting this following error in swift3
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
notificationReceived(notification: userInfo as [NSObject : AnyObject])
}
func notificationReceived(notification: [NSObject:AnyObject]) {
let viewController = window?.rootViewController
let view = viewController as? ViewController
view?.addNotification(
title: getAlert(notification: notification).0,
body: getAlert(notification: notification).1)
}
private func getAlert(notification: [NSObject:AnyObject]) -> (String, String) {
let aps = notification["aps"] as? NSDictionary
let alert = aps?["alert"] as? [String:AnyObject]
let title = alert?["title"] as? String
let body = alert?["body"] as? String
return (title ?? "-", body ?? "-")
}
But i am getting the following error "Swift 3.0 : Ambiguous reference to member 'Subscript' issue" at "let aps = notification["aps"] as? NSDictionary"
type converson
Change userInfo from NSDictionary to [String : Any]. and try once
let aps = notification["aps"] as? [String : Any]
or write as like
let aps = notification["aps" as NSString] as? [String:Any]
String is not convertable to NSObject
, just rename all your [NSObject:AnyObject]
to [String:Any]
with Swift 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With