Skip to content

Instantly share code, notes, and snippets.

@leoneparise
Last active February 23, 2017 00:32
Show Gist options
  • Save leoneparise/11e499d3c507642e22cd99fd9a5edc05 to your computer and use it in GitHub Desktop.
Save leoneparise/11e499d3c507642e22cd99fd9a5edc05 to your computer and use it in GitHub Desktop.
extension Notifications {
struct openUserProfile: RemoteNotificationType {
var userId:String
var title: String?
var alert: String?
static var name: Notification.Name {
return Notification.Name("LP_openUserProfile")
}
var name:Notification.Name {
return openUserProfile.name
}
var userInfo: [AnyHashable : Any] {
return [
"userId" : userId,
"title" : title ?? "",
"alert" : alert ?? ""
]
}
init(userId: String) {
self.userId = userId
}
init?(notification: Notification?) {
guard
let name = notification?.name,
let userId = notification?.userInfo?["userId"] as? String,
name == openUserProfile.name
else { return nil }
self.alert = notification?.userInfo?["alert"] as? String
self.title = notification?.userInfo?["title"] as? String
self.userId = userId
}
init?(userInfo: [AnyHashable : Any]) {
guard
let userId = userInfo["userId"] as? String,
let aps = userInfo["aps"] as? [AnyHashable : Any]
else { return nil }
self.title = userInfo["title"] as? String
self.alert = aps["alert"] as? String
self.userId = userId
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment