简体   繁体   中英

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.

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? 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. I'd appreciate any help!

Problem is not with Alamofire. It's to do with the external app's API and my iOS app not being able to redirect back.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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