我几个小时以来一直在弄清楚这个问题,我将我的应用与Dropbox联系起来。 我已经创建了演示应用程序,一切都在那里工作正常,但由于我已经在我的应用程序中合并,openurl委托返回false,我在dropbox中创建了新的应用程序,但仍然是同样的问题。
-canOpenURL: failed for URL: "dbapi-2://1/connect" - error: "This app is not allowed to query for scheme dbapi-2"
-canOpenURL: failed for URL: "dbapi-8-emm://1/connect" - error: "This app is not allowed to query for scheme dbapi-8-emm"
-canOpenURL: failed for URL: "dbapi-2://1/connect" - error: "This app is not allowed to query for scheme dbapi-2"
-canOpenURL: failed for URL: "dbapi-8-emm://1/connect" - error:"This app is not allowed to query for scheme dbapi-8-emm"
[ERROR] unable to verify link request
[ERROR] DropboxSDK: credentials not saved. Make sure you call -[DBSession handleOpenUrl:] in your app delegate's application:openURL:sourceApplication:annotation: method
app delegate中的代码:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if DBSession.shared().handleOpen(url as URL!) {
if DBSession.shared().isLinked() {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "didLinkToDropboxAccountNotification"), object: nil)
return true
}
}
return false
}
答案 0 :(得分:3)
完整教程请参阅this
确保您在.plist
中添加LSApplicationQueriesSchemes
一次
<key>LSApplicationQueriesSchemes</key>
<array>
<string>dbapi-2</string>
<string>dbapi-8-emm</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>db-APP_KEY</string>
</array>
</dict>
</array>
第二次错误:无法验证链接请求
func handleOpen(_ url: URL) -> Bool {
var expected: String = "\(self.appScheme())://\(kDBDropboxAPIVersion)/"
if !url.absoluteString.hasPrefix(expected) {
return false
}
var components: [Any] = url.path.pathComponents()
var methodName: String = components.count > 1 ? components[1] : nil
if methodName.isEqual("connect") {
var params: [AnyHashable: Any] = DBSession.parseURLParams(url.query)
var token: String? = (params["oauth_token"] as? String)
var secret: String? = (params["oauth_token_secret"] as? String)
var userId: String? = (params["uid"] as? String)
var state: String? = (params["state"] as? String)
var nonce: String? = UserDefaults.standard.object(forKey: kDBLinkNonce)
UserDefaults.standard.removeObject(forKey: kDBLinkNonce)
UserDefaults.standard.synchronize()
if !nonce.isEqual(state) {
DBLogError("unable to verify link request")
return false
}
self.updateAccessToken(token, accessTokenSecret: secret, for: userId)
}
if methodName.isEqual("cancel") {
DBLogInfo("DropboxSDK: user cancelled Dropbox link")
}
return true
}
答案 1 :(得分:0)
不幸的是,没有其他答案有效,我在Dropbox上删除了我的应用程序并创建了新的应用程序,并再次完成所有处理 瞧,一切都很好。
答案 2 :(得分:0)
https://github.com/dropbox/dropbox-sdk-obj-c/issues/182
您可以看一下。用rootviewcontroller替换viewcontroller对我有用。