Swift 3.0を使用してスラックインテグレーションで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)
}
Safariのアプリが開いその後、私は資格入力し、「承認」などの警告持ってタップし、「自分のアプリで開きます?」 私ははいをタップし、スラックコードから得られたと、私は次のリクエストを送信する私のアプリにリダイレクト:
//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()
}
}
}
コードがXcodeの8ベータ版で働いていたが、私は拡張子でXcodeの8の機能にアップデートする場合スラックウェブサイトからのリダイレクト後に呼び出されることはありません。
どうしたのですか? Slackログインプロセスを渡すより良い方法はありますか?
にする必要がありますが大漁で、問題を解決する助け、あなたはupvotedに答えています –