Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Requirements in AppDelegate for DeepLinking in Swift 3.
- class AppDelegate: UIResponder, UIApplicationDelegate {
- var window: UIWindow?
- var deepLink: RemoteNotificationDeepLink?
- func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
- handleDeepLink(app: app, url: url)
- //...
- return false
- }
- func handleDeepLink(app: UIApplication, url: URL) {
- guard url.host != nil else { return }
- let urlString = url.absoluteString
- let data = urlString.components(separatedBy: "/")
- guard data.count >= 3 else { return }
- let query = data[2]
- let parameter = data[3]
- guard query.range(of: "app") != nil else { return }
- let userInfo = ["app": parameter ]
- self.applicationHandleRemoteNotification(app, didReceiveRemoteNotification: userInfo)
- }
- func applicationHandleRemoteNotification(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
- if application.applicationState == UIApplicationState.background || application.applicationState == UIApplicationState.inactive {
- self.deepLink = RemoteNotificationDeepLink.create(userInfo)
- triggerDeepLinkIfPresent()
- }
- }
- func triggerDeepLinkIfPresent() -> Bool {
- let ret = (self.deepLink?.trigger() != nil)
- self.deepLink = nil
- return ret
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement