使用Alamofire.request重定向回应用

时间:2016-11-16 08:48:20

标签: ios swift xcode alamofire openurl

我正在使用Swift 3开发一个iOS应用程序(我是一个完整的Swift n00b。)我正在对外部应用程序进行身份验证,以获取访问令牌,但代码在验证后没有重定向回我的应用程序反对外部应用程序。

AppDelegate.swift

func application(_ application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: Any) -> Bool {
    print(url)
    DispatchQueue.main.async {
        print(url.scheme)
        if (url.scheme == "myapp"){
            print("i just caught a url and i feel fine and the url be says ", url)
        }
    }
    return true
}
处理来自外部应用程序的响应的类中的

            Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default)
                .responseJSON { response in
                    print(response)
                    if((response.result.value) != nil) {
                        let swiftyJsonVar = JSON(response.result.value!)
                        if let resData = swiftyJsonVar[key].string {
                            let autostart_data = swiftyJsonVar[key].string          
... snip ...
                            let url = URL(string: "extapp:///?key=\(data!)&redirect=\(myapp)://key")
                            UIApplication.shared.open(url!, options: [:])
... snip ...
                        }
                    }
            }

收到回复后,是否可以使用Alamofire重定向回我的应用程序?我过去两天一直在谷歌在线进行研究,并尝试了许多可能的解决方案,但到目前为止还没有实现。我很感激任何帮助!

1 个答案:

答案 0 :(得分:0)

问题不在于Alamofire。这与外部应用程序的API和我的iOS应用程序无法重定向有关。