重定向回Alamofire.request的应用程序
问题描述:
我正在Swift 3中开发一个iOS应用程序(我是一个完整的Swift n00b。)我对外部应用程序进行身份验证,以获取访问令牌,但代码是在对外部应用进行身份验证后,不会重定向回我的应用。重定向回Alamofire.request的应用程序
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,一旦响应收到?我在过去两天一直在谷歌上进行在线研究,并尝试了很多可能的解决方案,但到目前为止一无所获。我会很感激任何帮助!
答
问题不在于Alamofire。这是与外部应用程序的API和我的iOS应用程序无法重定向回来。
您是将用户重定向到Safari应用程序还是打开应用程序中的Web视图?如果您打开Safari应用程序,重定向应该由网站完成,而不是由应用程序执行 – milo526
我正在从外部auth应用程序重定向回我的原生应用程序。 – Mina
你在'Info.plist'中注册过你的应用程序吗? – Losiowaty