我使用了下面对我有用的代码,如果用户取消了保管箱登录或用户登录成功,这两种情况都有帮助
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
NSString *stringUrl = [url absoluteString];
if ([stringUrl containsString:@"cancel"]) {
// Handle if user cancelled the login
[[NSNotificationCenter defaultCenter] postNotificationName:@"dropboxRegistrationCancel" object:self];
return NO;
}
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
// From below notification u can fetch your data from Dropbox
[[NSNotificationCenter defaultCenter]
postNotificationName:@"isDropboxLinked"
object:[NSNumber numberWithBool:[[DBSession sharedSession] isLinked]]];
// Add whatever other url handling code your app requires here
}
return YES;
} return NO;
}
为了在登录后第一次获取文件,将此代码放置在您在viewDidLoad中显示文件列表的类中
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(isDropboxLinkedHandle:) name:@"isDropboxLinked" object:nil];
和 isDropboxLinkedHandle 的实现:
- (void)isDropboxLinkedHandle:(id)sender {
if ([[sender object] intValue]) {
// fetch all files
[[self restClient] loadMetadata:@"/"];
}
}
我希望它会有所帮助谢谢。