简体   繁体   English

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

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

I'm setting up an app where I want to show and modify data which are stored in a json-file.我正在设置一个应用程序,我想在其中显示和修改存储在 json 文件中的数据。 The files should be accessible either via an sftp-connection to a server or from an dropbox account.这些文件应该可以通过 sftp 连接到服务器或从 Dropbox 帐户访问。 Part of my app is a view where the user can select whether the file should be accessed via sftp or dropbox and type in the necessary credentials for sftp and the filename to be accessed.我的应用程序的一部分是一个视图,用户可以在该视图中 select 是否应该通过 sftp 或 dropbox 访问文件,并输入 sftp 的必要凭据和要访问的文件名。 Once the input is finished I start a method to check the inserted data and to check the connectivity to the specified source.输入完成后,我将启动一个方法来检查插入的数据并检查与指定源的连接性。

If dropbox is selected I try to launch the authorization within this method as follows:如果选择了保管箱,我尝试在此方法中启动授权,如下所示:

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
            )
          
        }

I'm using Xcode 12.3 and test with an iPhone 8 simulator.我正在使用 Xcode 12.3 并使用 iPhone 8 模拟器进行测试。

The sign-in workflow of dropbox is launched properly and I can type in my login data for dropbox and grant access. Dropbox 的登录工作流程已正确启动,我可以为 Dropbox 输入登录数据并授予访问权限。 But after allowing the access in the dropbox view the view stays and there is no jump back to my app.但是在 Dropbox 视图中允许访问后,视图会保持不变,并且不会跳转回我的应用程序。 Furthermore, I get the following error: 2021-01-16 06:52:20.212331+0100..[1805:55943] -canOpenURL: failed for URL: "dbapi-8-emm://1/connect?k=..........&s=" - error: "Der Vorgang konnte nicht abgeschlossen werden. (OSStatus-Fehler -10814.)此外,我收到以下错误: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。)

I checked several hints, not at least this: How to connect Dropbox API to iOS app with Swift 5 , but nothing fixed my issue.我检查了几个提示,至少是这样: How to connect Dropbox API to iOS app with Swift 5 ,但没有解决我的问题。

If I test my app on my iPhone, where the dropboxApp is installed, the shortened authorization workflow via this app leads to a jump back to my app, but the connection to the dropbox is not authorized.如果我在安装了 dropboxApp 的 iPhone 上测试我的应用程序,则通过此应用程序缩短的授权工作流程会导致跳转回我的应用程序,但与 Dropbox 的连接未经授权。

Within my dropbox account I have registered my app and created my app-key.在我的保管箱帐户中,我已经注册了我的应用程序并创建了我的应用程序密钥。 The permissions I request are "account.info.read", "files.content.write" and "files.content.read".我请求的权限是“account.info.read”、“files.content.write”和“files.content.read”。

I have changed the AppDelegate and the Info.plist as described in the documentation of SDK SwiftyDropbox:我已经按照 SDK SwiftyDropbox 的文档中的描述更改了 AppDelegate 和 Info.plist:

App-Delegate:应用委托:

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
}

Info.plist:信息列表:

<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>

Has anyone an idea where my problem is?有谁知道我的问题出在哪里? Thanks for your support.谢谢你的支持。

I could fix this problem meanwhile.我可以同时解决这个问题。

In the SceneDelegate the following code has to be added:在 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)
    }
}

Additionally: The initialization of the dropbox-connection has to be launched from the currently active view.另外:必须从当前活动视图启动保管箱连接的初始化。 In my case I wanted to use it on the version for iPad in SplitScreenMode and to launch a folder overview of the dropbox from a view modally shown on the DetailViewController.在我的情况下,我想在 SplitScreenMode 中的 iPad 版本上使用它,并从 DetailViewController 上模态显示的视图启动保管箱的文件夹概述。 The connection has to be launched from the modal view and not via a method from the DetailViewController连接必须从模式视图启动,而不是通过 DetailViewController 中的方法启动

暂无
暂无

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

相关问题 -canOpenURL:URL失败:“ fbauth2:/”-iOS 9错误:“(空)”(快速) - -canOpenURL: failed for URL: “fbauth2:/” - error: “(null)” for ios 9 (swift) swift3 - canOpenURL:URL 电话失败 - swift3 - canOpenURL: failed for URL tel -canOpenURL:URL失败:“ spotify:”-错误:“(null)” - -canOpenURL: failed for URL: “spotify:” - error: “(null)” -canOpenURL:URL失败:“fbauth2:/” - 错误:“(null)” - -canOpenURL: failed for URL: “fbauth2:/” - error: “(null)” Pinterest身份验证失败:-canOpenURL:URL失败:“pinterestsdk.v1:// oauth - Pinterest authentication fails: -canOpenURL: failed for URL: "pinterestsdk.v1://oauth 带有firebase canOpenURL的Swift Facebook Auth:URL失败:“ fbauth2:/”-错误:“该操作无法完成。 (OSStatus错误-10814。)” - Swift Facebook Auth with firebase canOpenURL: failed for URL: “fbauth2:/” - error: “The operation couldn’t be completed. (OSStatus error -10814.)” -canOpenURL:URL 失败:“fbauth2:/” - 错误:“操作无法完成。 (OSStatus 错误 -10814。)” SWIFT 5 FBDSKCoreKit 5 - -canOpenURL: failed for URL: “fbauth2:/” - error: “The operation couldn’t be completed. (OSStatus error -10814.)” SWIFT 5 FBDSKCoreKit 5 canOpenUrl失败,但openUrl成功 - canOpenUrl fails, but openUrl succeed -canOpenURL:URL失败:“fbauth2:/”(OSStatus错误-10814。)“ - -canOpenURL: failed for URL: “fbauth2:/” (OSStatus error -10814.)" -canOpenURL:由于 facebook 和其他社交网络的 URL 错误而失败 - -canOpenURL: failed for URL error for facebook and other social networks
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM