Swift 3.0을 사용하여 Slack 통합으로 iOS 앱을 개발합니다. 내가 로그인 프로세스 통과 방법 : "앱에서 열기"불황 로그인이 작동하지 않습니다. Swift 3.0
이func loginToSlackWithSafariBrowser() {
let scope = "channels%3Awrite+users%3Aread"
let clientId = "...myClientId"
let redirect_uri = "myAppDeepLink://"
let authURL = NSURL(string: "https://slack.com/oauth/authorize?client_id=\(clientId)&scope=\(scope)&redirect_uri=\(redirect_uri)")
guard let url = authURL else { return }
UIApplication.shared.openURL(url as URL)
}
그리고 사파리 응용 프로그램은 내가 자격 증명을 입력 열립니다 탭 "권한 부여"와 같은 경고가를 나는 네 누르고 내가 멋대로 코드에서 얻은 함께 다음 요청을 보내 내 앱에 리디렉션 :
//AppDelegate.swift
extension UIApplicationDelegate {
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: AnyObject) -> Bool {
self.exchangeCodeInURL(codeURL: url as NSURL)
return true
}
func exchangeCodeInURL(codeURL : NSURL) {
let clientId = "...myClientId"
let clientSecret = "...myclientSecret"
if let code = codeURL.query {
let request = NSMutableURLRequest(url: NSURL(string: "https://slack.com/api/oauth.access?client_id=\(clientId)&client_secret=\(clientSecret)&code=\(code)") as! URL)
request.httpMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "Accept")
URLSession.shared.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
print(response)
guard let unwrappedData = data else {return}
do {
if let rootObject = try JSONSerialization.jsonObject(with: unwrappedData, options: []) as? NSDictionary {
//Save and handle the token
print(rootObject)
}
}
catch {
print(error)
}
}).resume()
}
}
} 코드는 엑스 코드 8 베타에서 일하지만,
나는 엑스 코드로 확장 8 개 기능을 업데이트 할 때 Slack 웹 사이트에서 리디렉션 한 후 호출되지 않습니다.
무엇이 잘못 되었나요? Slack 로그인 프로세스를 전달하는 더 좋은 방법이 있습니까?
귀하의 제안은 upvoted에 답 풍어와 문제를 해결하는 데 도움이,이므로 –