我正在构建一个具有邀请链接的应用程序。
链接在 Android 应用程序中有效,但在 iOS 中,长链接有效,但短链接无效。
这是我在 appdelegate 中处理动态链接的代码
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
}
我已经在 didFinishLaunchingWithOptions 添加了这些代码
FirebaseOptions.defaultOptions()?.deepLinkURLScheme = Settings.deepLinkURLScheme
FirebaseApp.configure()
在 info.plist 我添加了这些
<key>CFBundleURLSchemes</key>
<array>
<string>homescreen</string>
<string>newtask</string>
<string>-----.page.link</string>
<string>https://-----.page.link</string>
<string>https://-----.me</string>
</array>
当我单击长链接时,它可以工作,但短链接返回 nil,并且我收到类似“动态链接 Web URL 查询项为空”的错误