简体   繁体   English

使用Alamofire.request重定向回应用

[英]Redirect back to app with Alamofire.request

I'm developing an iOS app in Swift 3 (I'm a complete Swift n00b.) I am authenticating against an external app, to get an access token back, but the code is not redirecting back to my app after authenticating against the external app. 我正在Swift 3中开发一个iOS应用程序(我是完整的Swift n00b。)我正在针对外部应用程序进行身份验证,以获取访问令牌,但是在针对外部应用程序进行身份验证后,代码并未重定向回我的应用程序应用程式。

AppDelegate.swift 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
}

in class that handles response from external app: 在处理来自外部应用程序的响应的类中:

            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 ...
                        }
                    }
            }

Is it possible to redirect back to my app, with Alamofire, once the response is received? 收到响应后,是否可以使用Alamofire重定向回我的应用程序? I have been researching online with Google for the past two days and have tried out many possible solutions, but have come to nothing so far. 在过去的两天里,我一直在与Google进行在线研究,并尝试了许多可能的解决方案,但到目前为止还没有任何结果。 I'd appreciate any help! 我将不胜感激!

Problem is not with Alamofire. 问题不在于Alamofire。 It's to do with the external app's API and my iOS app not being able to redirect back. 这与外部应用程序的API和我的iOS应用程序无法重定向回去有关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM