如何使用Swift 5将Dropbox API连接到iOS应用程序

如何使用Swift 5将Dropbox API连接到iOS应用程序,ios,swift,dropbox,Ios,Swift,Dropbox,我在将Dropbox API连接到我的应用程序时遇到问题。Dropbox API文档就在我眼前,我做的每件事都是按照上面写的那样。但是,在所示的一些方法中存在错误,我不知道如何替换所示的实体。我可以登录,但无法获取令牌,错误为:URL:“dbapi-2://1/connect”-错误:“操作无法完成。”。(OSStatus错误-10814)。” 这两种方法都是从DropboxAppi文档中复制的,但它们不起作用,我无法找到正确的解决方案。适用于SwiftHydropbox 在AppDelegat

我在将Dropbox API连接到我的应用程序时遇到问题。Dropbox API文档就在我眼前,我做的每件事都是按照上面写的那样。但是,在所示的一些方法中存在错误,我不知道如何替换所示的实体。我可以登录,但无法获取令牌,错误为:URL:“dbapi-2://1/connect”-错误:“操作无法完成。”。(OSStatus错误-10814)。”

这两种方法都是从DropboxAppi文档中复制的,但它们不起作用,我无法找到正确的解决方案。

适用于SwiftHydropbox

AppDelegate.swift中

import SwiftyDropbox

      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        /// Add Dropbox
        DropboxClientsManager.setupWithAppKey("<YOUR_APP_KEY>")
        
        return true
      }


 func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    var canHandleUrl = false

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

          }
        }
      canHandleUrl = DropboxClientsManager.handleRedirectURL(url, completion: oauthCompletion)
    }
    
    return canHandleUrl
  }
你的Info.plist应该包含这些内容,以便重定向返回到你的应用程序

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleIdentifier</key>
            <string></string>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string><YOUR API KEY></string>
            </array>
        </dict>
    </array>
    <key>LSApplicationQueriesSchemes</key>
    <array>
    <string>dbapi-8-emm</string>
    <string>dbapi-2</string>
    </array>
CbundleUrlTypes
CbundleIdentifier
CbundleTypeRole
编辑
循环流化床锅炉方案
LSApplicationQueriesSchemes
dbapi-8-emm
dbapi-2

SwiftHydropbox是cocoapod库吗?如果不是,您是如何将其添加到项目中的。如果是,您是打开工作区文件还是项目文件。当然,它是连接的,我一步一步地完成了所有操作。显然,某个地方出了问题,如果没有进一步的信息,我们几乎不可能在安装后找到它的原因Xcode说可以转换成Swift 5,如果我不这样做,那么就没有错误,但我仍然不能超越授权。在它之后,会出现一个窗口:“应用程序名称“想要:查看基本信息…等等。但如果我按下控制台中的任何按钮-无任何提示,我会看到错误:2020-08-14 15:38:52.477148+0300 MusicLayer[14334:982728]-canOpenURL:URL失败:“dbapi-8”-emm://1/connect?k=5nski8h24edy1h6&s=-错误:“操作无法完成。(OSStatus错误-10814)。”
import SwiftyDropBox

     @IBAction func connectDropboxSwitchClicked(_ sender: Any) {
        if connectDropboxSwitch.isOn {
          
          /// https://stackoverflow.com/a/39546950/14414215
          /// openURL deprecated
          let scopeRequest = ScopeRequest(scopeType: .user, scopes: ["account_info.read","files.content.write"], includeGrantedScopes: false)
          DropboxClientsManager.authorizeFromControllerV2(
            UIApplication.shared,
            controller: self,
            loadingStatusDelegate: nil,
            //          openURL: { (url: URL) -> Void in UIApplication.shared.openURL(url) },
            openURL: { (url: URL) -> Void in UIApplication.shared.open( url, options: [:])},
            scopeRequest: scopeRequest
          )
          
        } else {
          print(" connectDropbox Switch:\(connectDropbox)")
        }
      }
<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleIdentifier</key>
            <string></string>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string><YOUR API KEY></string>
            </array>
        </dict>
    </array>
    <key>LSApplicationQueriesSchemes</key>
    <array>
    <string>dbapi-8-emm</string>
    <string>dbapi-2</string>
    </array>