Advertisement
krotoff

RemoteNotificationDeepLink

Jul 21st, 2017
1,379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.56 KB | None | 0 0
  1. //Class for handling DeepLink in Swift 3.
  2.  
  3. class RemoteNotificationDeepLink: NSObject {
  4.     var article: String = ""
  5.    
  6.     class func create(_ userInfo: [AnyHashable: Any]) -> RemoteNotificationDeepLink? {
  7.         let info = userInfo as NSDictionary
  8.         guard let articleID = info.object(forKey: "app") as? String else {
  9.             return nil
  10.         }
  11.        
  12.         var ret: RemoteNotificationDeepLink? = nil
  13.         if !articleID.isEmpty {
  14.             ret = RemoteNotificationDeepLinkArticle(articleStr: articleID)
  15.         }
  16.         return ret
  17.     }
  18.    
  19.     fileprivate override init() {
  20.         self.article = ""
  21.         super.init()
  22.     }
  23.    
  24.     fileprivate init(articleStr: String) {
  25.         self.article = articleStr
  26.         super.init()
  27.     }
  28.    
  29.     final func trigger() {
  30.         DispatchQueue.main.async {
  31.             self.triggerImp() { _ in
  32.                 // do nothing
  33.             }
  34.         }
  35.     }
  36.    
  37.     fileprivate func triggerImp(_ completion: ((AnyObject?) -> (Void))) {
  38.         completion(nil)
  39.     }
  40. }
  41.  
  42. class RemoteNotificationDeepLinkArticle: RemoteNotificationDeepLink {
  43.     var articleID: String!
  44.    
  45.     override init(articleStr: String) {
  46.         self.articleID = articleStr
  47.         super.init(articleStr: articleStr)
  48.     }
  49.    
  50.     fileprivate override func triggerImp(_ completion: ((AnyObject?) -> (Void))) {
  51.         super.triggerImp() { _ in
  52.             if let strID = self.articleID, let id = Int(strID) {
  53.                 //handle id
  54.             }
  55.             completion(nil)
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement