我无法让我的应用链接到 iOS 上的保管箱。
我创建 session 并询问它是否已链接...如果没有,它会打开 Dropbox 以获得授权。我说是,然后它返回到我的应用程序并发送通知以开始上传。
但是 isLinked 仍然是 NO,所以如果我尝试上传文件失败。任何建议表示赞赏。
有趣的是,从未调用 -sessionDidReceiveAuthorizationFailure: userId: 委托(delegate)方法。
-(void)connectToDropbox{
if (!dbSession) {
dbSession = [[DBSession alloc] initWithAppKey:@"key"
appSecret:@"secret"
root:kDBRootDropbox];
dbSession.delegate = self;
[DBSession setSharedSession:dbSession];
}
if ([[DBSession sharedSession] isLinked]) {
[self beginUpload:nil];
} else {
[[DBSession sharedSession] linkFromController:self.currentViewController];
}
}
- (void)beginUpload:(NSNotification *)note {
if (![[DBSession sharedSession] isLinked]) {
NSError * error = [NSError errorWithDomain:@"myApp"
code:0
userInfo:@{NSLocalizedDescriptionKey : @"Could not link to Dropbox"}];
[[NSNotificationCenter defaultCenter] postNotificationName:kErrorDidOccurNotification object:error];
NSLog(@"File upload failed with error: %@", error);
return;
}
///do the upload if we make it here.
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation NS_AVAILABLE_IOS(4_2){
if ([sourceApplication isEqualToString:@"com.getdropbox.Dropbox"]) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"beginDropboxUpload" object:nil];
}
/// more code
}
最佳答案
您在应用委托(delegate)中的代码不正确。你需要这样的东西:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation NS_AVAILABLE_IOS(4_2) {
if ([[DBSession sharedSession] handleOpenURL:url]) {
NSString *query = url.query;
if ([[url absoluteString] rangeOfString:@"cancel"].location == NSNotFound) { // NO_I18N
[[NSNotificationCenter defaultCenter] postNotificationName:@"beginDropboxUpload" object:nil];
} else {
// Link cancelled
}
} else {
// Something other than Dropbox
}
}
关于ios - iOS 上的 Dropbox API 无法链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33306381/