iOS 上的 Dropbox API 无法 link
Dropbox API on iOS fails to link
我无法将我的应用 link 上传到 iOS 上的保管箱。
我创建会话并询问它是否已 linked...如果不是,它会打开 Dropbox 以获得授权。我说是,它 returns 到我的应用程序并发送通知以开始上传。
但是isLinked还是NO,所以我尝试上传文件失败。任何建议表示赞赏。
有趣的是,从未调用 -sessionDidReceiveAuthorizationFailure: userId: 委托方法。
-(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
}
您在应用委托中的代码不正确。你需要这样的东西:
- (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
}
}
我无法将我的应用 link 上传到 iOS 上的保管箱。
我创建会话并询问它是否已 linked...如果不是,它会打开 Dropbox 以获得授权。我说是,它 returns 到我的应用程序并发送通知以开始上传。
但是isLinked还是NO,所以我尝试上传文件失败。任何建议表示赞赏。
有趣的是,从未调用 -sessionDidReceiveAuthorizationFailure: userId: 委托方法。
-(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
}
您在应用委托中的代码不正确。你需要这样的东西:
- (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
}
}