繁体   English   中英

将 Dropbox 连接到 swift 5 失败并出现错误 -canOpenURL: failed

[英]connecting Dropbox to swift 5 fails with error -canOpenURL: failed

我正在设置一个应用程序,我想在其中显示和修改存储在 json 文件中的数据。 这些文件应该可以通过 sftp 连接到服务器或从 Dropbox 帐户访问。 我的应用程序的一部分是一个视图,用户可以在该视图中 select 是否应该通过 sftp 或 dropbox 访问文件,并输入 sftp 的必要凭据和要访问的文件名。 输入完成后,我将启动一个方法来检查插入的数据并检查与指定源的连接性。

如果选择了保管箱,我尝试在此方法中启动授权,如下所示:

if newAccess.credentials.accesstype == .dropbox {
            let scopeRequest = ScopeRequest(scopeType: .user, scopes: ["account_info.read"], includeGrantedScopes: false)
            DropboxClientsManager.authorizeFromControllerV2(
                UIApplication.shared,
                controller: self,
                loadingStatusDelegate: nil,
              openURL: { (url: URL) -> Void in UIApplication.shared.open(url, options: [:], completionHandler: nil) },
                scopeRequest: scopeRequest
            )
          
        }

我正在使用 Xcode 12.3 并使用 iPhone 8 模拟器进行测试。

Dropbox 的登录工作流程已正确启动,我可以为 Dropbox 输入登录数据并授予访问权限。 但是在 Dropbox 视图中允许访问后,视图会保持不变,并且不会跳转回我的应用程序。 此外,我收到以下错误:2021-01-16 06:52:20.212331+0100..[1805:55943] -canOpenURL: failed for URL: "dbapi-8-emm://1/connect?k=. .........&s =“ - 错误:“Der Vorgang konnte nicht abgeschlossen werden。(OSStatus-Fehler -10814。)

我检查了几个提示,至少是这样: How to connect Dropbox API to iOS app with Swift 5 ,但没有解决我的问题。

如果我在安装了 dropboxApp 的 iPhone 上测试我的应用程序,则通过此应用程序缩短的授权工作流程会导致跳转回我的应用程序,但与 Dropbox 的连接未经授权。

在我的保管箱帐户中,我已经注册了我的应用程序并创建了我的应用程序密钥。 我请求的权限是“account.info.read”、“files.content.write”和“files.content.read”。

我已经按照 SDK SwiftyDropbox 的文档中的描述更改了 AppDelegate 和 Info.plist:

应用委托:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    DropboxClientsManager.setupWithAppKey(dropboxAppKey) // my key
    return true
}


// MARK: UISceneSession Lifecycle

func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
   
}

func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
    
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    let oauthCompletion: DropboxOAuthCompletion = {
      if let authResult = $0 {
          switch authResult {
          case .success:
              print("Success! User is logged into DropboxClientsManager.")
          case .cancel:
              print("Authorization flow was manually canceled by user!")
          case .error(_, let description):
              print("Error: \(String(describing: description))")
          }
      }
    }
    let canHandleUrl = DropboxClientsManager.handleRedirectURL(url, completion: oauthCompletion)
    return canHandleUrl
}

信息列表:

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>dbapi-8-emm</string>
        <string>dbapi-2</string>
    </array>
<key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleIdentifier</key>
                <string></string>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>db-...myKey...</string>
                </array>
        </dict>
    </array>

有谁知道我的问题出在哪里? 谢谢你的支持。

我可以同时解决这个问题。

在 SceneDelegate 中必须添加以下代码:

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    if let url = URLContexts.first?.url {
        let oauthCompletion: DropboxOAuthCompletion = {
          if let authResult = $0 {
              switch authResult {
              case .success:
                  print("Success! User is logged into DropboxClientsManager.")
              case .cancel:
                  print("Authorization flow was manually canceled by user!")
              case .error(_, let description):
                  print("Error: \(String(describing: description))")
              }
          }
        }
        DropboxClientsManager.handleRedirectURL(url, completion: oauthCompletion)
    }
}

另外:必须从当前活动视图启动保管箱连接的初始化。 在我的情况下,我想在 SplitScreenMode 中的 iPad 版本上使用它,并从 DetailViewController 上模态显示的视图启动保管箱的文件夹概述。 连接必须从模式视图启动,而不是通过 DetailViewController 中的方法启动

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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