0

I am building an app that has invite links.

Links are working in Android app but in iOS, long link working but short link not.

here's my code in appdelegate to handle dynamic link

func handleDynamicLink(_ dynamicLink: DynamicLink?) -> Bool {
        guard let dynamicLink = dynamicLink else { return false }
        guard let deepLink = dynamicLink.url else { return false }
        let queryItems = URLComponents(url: deepLink, resolvingAgainstBaseURL: true)?.queryItems
        let invitedBy = queryItems?.filter({(item) in item.name == "invitedby"}).first?.value
        let user = Auth.auth().currentUser
        if user != nil
        {
            print("invitedBy:\(invitedBy ?? "nil")")
            //Add to user's team
            UserObject().addTeamMember(userId: invitedBy!, delegate: nil)
            
        }
        else
        {
            self.invitedBy = invitedBy!
        }

     return true
    }




func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
        
        let sourceApplication = options[UIApplication.OpenURLOptionsKey.sourceApplication] as! String?
        print("open url: \(url)")
        if url.absoluteString == "newtask" {
            NotificationCenter.default.post(name:NSNotification.Name("newtask"), object: nil)
        }
        if FUIAuth.defaultAuthUI()?.handleOpen(url, sourceApplication: sourceApplication) ?? false {
            return true
        }
        if DynamicLinks.dynamicLinks().shouldHandleDynamicLink(fromCustomSchemeURL: url)
        {
            let dynamicLink = DynamicLinks.dynamicLinks().dynamicLink(fromCustomSchemeURL: url)
            print("dynamicLink: \(dynamicLink!.url?.absoluteString ?? "nil")")
            return handleDynamicLink(dynamicLink)
        }
        // other URL handling goes here.
        if url.scheme == "homescreen"
        {
            print("NavigateToHomeScreen")
            if let tabbarController = self.window?.rootViewController as? UITabBarController
            {
                tabbarController.selectedIndex = 0
                let planNavigationController = tabbarController.viewControllers![0] as! UINavigationController
                planNavigationController.popToRootViewController(animated: false)
            }
            return true
        }
        else if url.scheme == "newtask"
        {
            print("NavigateToNewTask")
            if let tabbarController = self.window?.rootViewController as? UITabBarController
            {
                tabbarController.selectedIndex = 0
                let planNavigationController = tabbarController.viewControllers![0] as! UINavigationController
                planNavigationController.popToRootViewController(animated: false)
                planNavigationController.viewControllers[0].performSegue(withIdentifier: "toTask", sender: self)
            }
            return true
        }
        else
        {
            print("url.scheme : \(url.scheme ?? "nil")")
        }
        return false
    }

i've add these codes in didFinishLaunchingWithOptions

FirebaseOptions.defaultOptions()?.deepLinkURLScheme = Settings.deepLinkURLScheme
FirebaseApp.configure()

and in info.plist i've add these

    <key>CFBundleURLSchemes</key>
    <array>
        <string>homescreen</string>
        <string>newtask</string>
        <string>-----.page.link</string>
        <string>https://-----.page.link</string>
        <string>https://-----.me</string>
    </array>

When I click the long link it works but shortlink returns nil and i get error like "Dynamic link web URL query item is empty"

Oğuz
  • 3
  • 4

1 Answers1

0

Make sure you have added your domain value in Associated domain like "dev.hnb.com"

enter image description here

// MARK: - Deep Linking

func application(_ application: UIApplication, continue userActivity: NSUserActivity,
                 restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool 
{
    let myUrl: String? = userActivity.webpageURL?.absoluteString
    print(myUrl)
}
------------------------------------------------------------------------
AASA FILE FOR Verifies
--------------------
    {
      "applinks": {
        "apps": [],
        "details": [
          {
            "appID": "******1738.com.app",
            "components": [
              {
                "/": "/documentationsucksforios13",
                "comment": "This documentation is awful"
              },
              {
              "/": "/customer/account/createpassword/*",
                   "?": { "_query_id": "?*" },
                            "?": { "_query_token": "?*" },
                    "?": { "id": "?*" },
                            "?": { "token": "?*" }              
              },
        {
              "/": "/customer/account/createpassword/*",
                    "?": { "id": "?*" },
                            "?": { "token": "?*" }              
              }
            ],
            "paths": [ "/documentationsucksforios12" ]
          }
        ]
      },
      "webcredentials": {
        "apps": [ "******1738.com.app" ]
      }
    }
Hardik Bar
  • 86
  • 6