简体   繁体   English

使用 Dropbox SDK 时无法调用 AppDelegate openURL( )

[英]Unable to call AppDelegate openURL( ) while using the Dropbox SDK

I'm trying to add Dropbox authentication to my app, but it's showing me this error:我正在尝试将 Dropbox 身份验证添加到我的应用程序,但它向我显示此错误:

DropboxSDK: app delegate does not implement application:openURL:sourceApplication:annotation:

Below is the code in my app delegate:以下是我的应用程序委托中的代码:

let dbSession = DBSession(appKey: dbAppKey, appSecret: dbAppSecret, root: kDBRootDropbox)
DBSession.setSharedSession(dbSession)

func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {

    if DBChooser.defaultChooser().handleOpenURL(url){
        return true
    }
    else if DBSession.sharedSession().handleOpenURL(url){

        if DBSession.sharedSession().isLinked(){
            return true
        }
    }
    return false
}

I had created an NSObject for authentication and handling other operations related to Dropbox API.我创建了一个 NSObject 用于身份验证和处理与 Dropbox API 相关的其他操作。 Below is my authentication code:下面是我的验证码:

if !DBSession.sharedSession().isLinked(){
    DBSession.sharedSession().linkFromController(viewController)
}
else{
    delegate.authenticationStatus!(true, error: nil)
}

I'm getting this error after it's successfully logged in. I had also set LSApplicationQueriesSchemes in my plist and also added the URL types.成功登录后出现此错误。我还在 plist 中设置了 LSApplicationQueriesSchemes 并添加了 URL 类型。 I'm unable to find where I'm making a mistake.我无法找到我犯错的地方。

Also I'm trying to check if Dropbox app is present or not using此外,我正在尝试检查 Dropbox 应用程序是否存在或未使用

if UIApplication.sharedApplication().canOpenURL(NSURL(string: "dbapi-1://")!){
}

But it's giving me below error:但它给了我以下错误:

canOpenURL: failed for URL: "dbapi-1://" - error: "(null)"
canOpenURL: failed for URL: "dbapi-2://1/connect" - error: "(null)"

Any help will be appreciated.任何帮助将不胜感激。

Thanks in advance.提前致谢。

Your app delegate appears to implement a different openURL signature than what the SDK expects.您的应用程序委托似乎实现了与 SDK 预期不同的openURL签名。

Change the signature to this instead:改为将签名更改为:

func application(application: UIApplication, openURL url: NSURL,
    sourceApplication: String?, annotation: AnyObject) -> Bool {

Do take note that this method has been marked deprecated in the iOS 9 SDK.请注意,此方法已在 iOS 9 SDK 中标记为deprecated It will continue to work as expected for a while though.不过,它会继续按预期工作一段时间。

From or after iOS 13 adding the following func to SceneDelegate.swift seems to work:从 iOS 13 开始或之后,将以下 func 添加到 SceneDelegate.swift 似乎有效:

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

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

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