Swift Firebase动态链接:shorteningURL不起作用

时间:2018-12-25 10:12:20

标签: ios swift firebase firebase-dynamic-links

面对一些问题,以便从firebase动态链接生成shortURL,我能够得到longDynamicLink url。但是

这是我的代码,我正在按https://firebase.google.com/docs/dynamic-links/ios/create使用以下步骤,DynamicLinkComponents.shortenURL完成未得到调用,并且也没有错误

guard let longDynamicLink = linkBuilder.url else { return "test" }
print("The long URL is: \(longDynamicLink)")

DynamicLinkComponents.shortenURL(longDynamicLink, options: nil) { url, warnings, error in
    guard let url = url, error != nil else { return }
    print("The short URL is: \(url)")
}

DynamicLinkComponents.shortenURL此部分未执行

2 个答案:

答案 0 :(得分:1)

尝试此代码。这段代码对我来说很好。

test('if the recovery state is true should set the state to the false', () => {
      wrapper.setState({ recovery: true })
      //Check if the state is true initially
      expect(wrapper.state().recovery).toBeTruthy()
      //Calling the toggleRecovery()
      wrapper.instance().toggleRecovery({ 
          preventDefault: () => {
      })
      expect(wrapper.state().recovery).toBeFalsy()
      expect(props.reset).toHaveBeenCalled()
    })

答案 1 :(得分:0)

  1. 将此添加到“应用功能-关联的域”中,然后输入-applinks:yourdomain.com

enter image description here

  1. 在您的ViewController中添加

    guard let link = URL(string: "https://www.yourdomain.com/share_location.html?Id=\(RandomID)&uid=\(uid)") else { return }
        let dynamicLinksDomain = "yourdomain.page.link"
    
    
        let components = DynamicLinkComponents(link: link, domain: dynamicLinksDomain)
        // [START shortLinkOptions]
        let options = DynamicLinkComponentsOptions()
        options.pathLength = .unguessable
        components.options = options
        // [END shortLinkOptions]
    
        // [START shortenLink]
        components.shorten { (shortURL, warnings, error) in
            // Handle shortURL.
            if let error = error {
                print(error.localizedDescription)
                return
            }
            print(shortURL?.absoluteString ?? "")
            self.shortLink = shortURL
        }