Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Class for handling DeepLink in Swift 3.
- class RemoteNotificationDeepLink: NSObject {
- var article: String = ""
- class func create(_ userInfo: [AnyHashable: Any]) -> RemoteNotificationDeepLink? {
- let info = userInfo as NSDictionary
- guard let articleID = info.object(forKey: "app") as? String else {
- return nil
- }
- var ret: RemoteNotificationDeepLink? = nil
- if !articleID.isEmpty {
- ret = RemoteNotificationDeepLinkArticle(articleStr: articleID)
- }
- return ret
- }
- fileprivate override init() {
- self.article = ""
- super.init()
- }
- fileprivate init(articleStr: String) {
- self.article = articleStr
- super.init()
- }
- final func trigger() {
- DispatchQueue.main.async {
- self.triggerImp() { _ in
- // do nothing
- }
- }
- }
- fileprivate func triggerImp(_ completion: ((AnyObject?) -> (Void))) {
- completion(nil)
- }
- }
- class RemoteNotificationDeepLinkArticle: RemoteNotificationDeepLink {
- var articleID: String!
- override init(articleStr: String) {
- self.articleID = articleStr
- super.init(articleStr: articleStr)
- }
- fileprivate override func triggerImp(_ completion: ((AnyObject?) -> (Void))) {
- super.triggerImp() { _ in
- if let strID = self.articleID, let id = Int(strID) {
- //handle id
- }
- completion(nil)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement