为什么 OAuth 重定向在 iOS 13 中不起作用,但在 iOS 12 中却起作用?
Why does OAuth redirect not work in iOS 13 but it does in iOS 12?
我正在开发我的应用程序,它应该与 Dropbox 交互、下载文件、读写文件然后上传。问题是该应用程序在 iOS 12 中运行良好但在 iOS 13 中不起作用。我认为问题出在这里是因为代码未执行并且在 iOS 12 模拟器中是的。
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
这是视图控制器中的代码
import UIKit
import Foundation
import SwiftyDropbox
class viewCon:UIViewController {
@IBOutlet weak var lab: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func refresh(_ sender: Any) {
let client = DropboxClientsManager.authorizedClient
if client == nil { lab.text = "Not logged"} else {lab.text = "Logged"}
}
@IBAction func login(_ sender: Any) {
DropboxClientsManager.authorizeFromController(UIApplication.shared, controller:self, openURL: { (url: URL) -> Void in UIApplication.shared.open(url)})
}
@IBAction func download(_ sender: Any) {
}
}
这是AppDelegate.swift
import UIKit
import SwiftyDropbox
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print("init")
DropboxClientsManager.setupWithAppKey("********")
// Override point for customization after application launch.
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print("1")
if let authResult = DropboxClientsManager.handleRedirectURL(url as URL) {
print("2")
switch authResult {
case .success(_): //(let token)
//print("Success! User is logged into Dropbox with token: \(token)")
print("Success! User is logged into Dropbox.")
case .cancel:
print("User canceld OAuth flow.")
case .error(let error, let description):
print("Error \(error): \(description)")
}
} else {
print("3")
}
return true
}
}
这是我的info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>db-*********</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>dbapi-8-emm</string>
<string>dbapi-2</string>
</array>
我用 print("x") 来了解代码是否被执行,我注意到 in ios12 没问题,in iOS 13 不起作用。有什么想法吗?
在 SceneDelegate 中添加这个函数
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
for urlContext in URLContexts {
let url = urlContext.url
if let authResult = DropboxClientsManager.handleRedirectURL(url) {
switch authResult {
case .success:
print("Success! User is logged into account.")
case .cancel:
print("Authorization flow was manually canceled by user!")
case .error(_, let description):
print("Error: \(description)")
}
}
}
}
我正在开发我的应用程序,它应该与 Dropbox 交互、下载文件、读写文件然后上传。问题是该应用程序在 iOS 12 中运行良好但在 iOS 13 中不起作用。我认为问题出在这里是因为代码未执行并且在 iOS 12 模拟器中是的。
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
这是视图控制器中的代码
import UIKit
import Foundation
import SwiftyDropbox
class viewCon:UIViewController {
@IBOutlet weak var lab: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func refresh(_ sender: Any) {
let client = DropboxClientsManager.authorizedClient
if client == nil { lab.text = "Not logged"} else {lab.text = "Logged"}
}
@IBAction func login(_ sender: Any) {
DropboxClientsManager.authorizeFromController(UIApplication.shared, controller:self, openURL: { (url: URL) -> Void in UIApplication.shared.open(url)})
}
@IBAction func download(_ sender: Any) {
}
}
这是AppDelegate.swift
import UIKit
import SwiftyDropbox
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
print("init")
DropboxClientsManager.setupWithAppKey("********")
// Override point for customization after application launch.
return true
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print("1")
if let authResult = DropboxClientsManager.handleRedirectURL(url as URL) {
print("2")
switch authResult {
case .success(_): //(let token)
//print("Success! User is logged into Dropbox with token: \(token)")
print("Success! User is logged into Dropbox.")
case .cancel:
print("User canceld OAuth flow.")
case .error(let error, let description):
print("Error \(error): \(description)")
}
} else {
print("3")
}
return true
}
}
这是我的info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>db-*********</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>dbapi-8-emm</string>
<string>dbapi-2</string>
</array>
我用 print("x") 来了解代码是否被执行,我注意到 in ios12 没问题,in iOS 13 不起作用。有什么想法吗?
在 SceneDelegate 中添加这个函数
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
for urlContext in URLContexts {
let url = urlContext.url
if let authResult = DropboxClientsManager.handleRedirectURL(url) {
switch authResult {
case .success:
print("Success! User is logged into account.")
case .cancel:
print("Authorization flow was manually canceled by user!")
case .error(_, let description):
print("Error: \(description)")
}
}
}
}