用于iOS的Dropbox SDK-检测到登录取消
我开始使用用于iOS的DropBox SDK,我看到用于检测登录是否成功的代码如下: 在AppDelegate中:用于iOS的Dropbox SDK-检测到登录取消,ios,dropbox,Ios,Dropbox,我开始使用用于iOS的DropBox SDK,我看到用于检测登录是否成功的代码如下: 在AppDelegate中: - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { if ([[DBSession sharedSession] isLinked]) { // Success } else { // Failed }
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if ([[DBSession sharedSession] isLinked])
{
// Success
}
else
{
// Failed
}
return YES;
}
如果发生故障,我如何确定原因?我想至少区分错误和取消。以识别取消
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSArray *components = [[url path] pathComponents];
NSString *methodName = [components count] > 1 ? [components objectAtIndex:1] : nil;
if ([methodName isEqual:@"cancel"]) {
NSLog(@"Dropbox link Cancelled");
}
}
- (void)isDropboxLinkedHandle:(id)sender {
if ([[sender object] intValue]) {
// fetch all files
[[self restClient] loadMetadata:@"/"];
}
}
以识别取消按钮
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSArray *components = [[url path] pathComponents];
NSString *methodName = [components count] > 1 ? [components objectAtIndex:1] : nil;
if ([methodName isEqual:@"cancel"]) {
NSLog(@"Dropbox link Cancelled");
}
}
- (void)isDropboxLinkedHandle:(id)sender {
if ([[sender object] intValue]) {
// fetch all files
[[self restClient] loadMetadata:@"/"];
}
}
如果有人遇到这个问题,并对巴拉的答案感到困惑,那是因为该方法
handleOpenURL
已经过时了。Dropbox现在使用openURL
。openURL进入应用程序委托
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(NSString *)source annotation:(id)annotation {
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"App linked successfully!");
// At this point you can start making API calls
// Send notification to load an initial root dropbox path
[[NSNotificationCenter defaultCenter] postNotificationName:@"getDropboxRoot" object:self];
}else{// Add whatever other url handling code your app requires here in this else
//if the user clicks cancel that will appear here in the methodName variable,
//we post a notification to wherever we want.
NSArray* components = [[url path] pathComponents];
NSString *methodName = [components count] > 1 ? [components objectAtIndex:1] : nil;
if ([methodName isEqual:@"cancel"]) {
NSLog(@"Dropbox link Cancelled");
[[NSNotificationCenter defaultCenter] postNotificationName:@"dropboxRegistrationCancel" object:self];
}
}
return YES;
}
return NO;}
基本上,要检测取消,您只需检查url组件中的单词“cancel”,如果找到,您只需在应用程序的任何位置发送通知,告知用户取消了该过程
您的通知发布的观察员代码,将其放在您想要检测上面发布的通知的任何位置
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dropboxRegistrationCancel)
name:@"dropboxRegistrationCancel"
object:nil];
-(void) dropboxRegistrationCancel{
/*do stuff here that you want to do when the @"dropboxRegistrationCancelled" is triggered*/}
如果有人遇到这个问题,并对巴拉的答案感到困惑,那是因为该方法
handleOpenURL
已经过时了。Dropbox现在使用openURL
。openURL进入应用程序委托
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(NSString *)source annotation:(id)annotation {
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"App linked successfully!");
// At this point you can start making API calls
// Send notification to load an initial root dropbox path
[[NSNotificationCenter defaultCenter] postNotificationName:@"getDropboxRoot" object:self];
}else{// Add whatever other url handling code your app requires here in this else
//if the user clicks cancel that will appear here in the methodName variable,
//we post a notification to wherever we want.
NSArray* components = [[url path] pathComponents];
NSString *methodName = [components count] > 1 ? [components objectAtIndex:1] : nil;
if ([methodName isEqual:@"cancel"]) {
NSLog(@"Dropbox link Cancelled");
[[NSNotificationCenter defaultCenter] postNotificationName:@"dropboxRegistrationCancel" object:self];
}
}
return YES;
}
return NO;}
基本上,要检测取消,您只需检查url组件中的单词“cancel”,如果找到,您只需在应用程序的任何位置发送通知,告知用户取消了该过程
您的通知发布的观察员代码,将其放在您想要检测上面发布的通知的任何位置
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dropboxRegistrationCancel)
name:@"dropboxRegistrationCancel"
object:nil];
-(void) dropboxRegistrationCancel{
/*do stuff here that you want to do when the @"dropboxRegistrationCancelled" is triggered*/}
我已经使用了下面的代码,它为我工作,它有助于在这两种情况下,如果用户取消了dropbox登录或用户登录成功
- (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:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSArray *components = [[url path] pathComponents];
NSString *methodName = [components count] > 1 ? [components objectAtIndex:1] : nil;
if ([methodName isEqual:@"cancel"]) {
NSLog(@"Dropbox link Cancelled");
}
}
- (void)isDropboxLinkedHandle:(id)sender {
if ([[sender object] intValue]) {
// fetch all files
[[self restClient] loadMetadata:@"/"];
}
}
我希望这会有帮助,谢谢。我使用了下面的代码,这对我来说很有用,如果用户取消了dropbox登录或用户成功登录,这两种情况都会有帮助
- (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:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSArray *components = [[url path] pathComponents];
NSString *methodName = [components count] > 1 ? [components objectAtIndex:1] : nil;
if ([methodName isEqual:@"cancel"]) {
NSLog(@"Dropbox link Cancelled");
}
}
- (void)isDropboxLinkedHandle:(id)sender {
if ([[sender object] intValue]) {
// fetch all files
[[self restClient] loadMetadata:@"/"];
}
}
我希望它能对你有所帮助,谢谢。-(BOOL)application:(UIApplication*)application handleopeanurl:(NSURL*)url{if([[DBSession sharedSession]handleopeanurl:url]){if([[DBSession sharedSession]isLinked]){ALog(@“App linked successfully!”);//此时你可以开始进行API调用了}return YES;}return NO;}我找不到如何识别故障原因。。但是应该可以帮你找到原因,我想是的。@Bala我在使用DropBox SDK,我不控制UIWebView,所以我不能添加我自己的代理。。。除非有办法这样做?是的,你是对的!。我们无法控制他们的委托方法。最新的Dropbox SDK提供了查找失败原因的功能。请下载最新的SDK并重试。有一个愉快的编码。-(BOOL)应用程序:(UIApplication*)应用程序handleopeanurl:(NSURL*)url{if([[DBSession sharedSession]handleopeanurl:url]){if([[DBSession sharedSession]isLinked]){ALog(@“App linked successfully!”);//此时您可以开始进行API调用了}return YES;}return NO;}我找不到如何识别故障原因。。但是应该可以帮你找到原因,我想是的。@Bala我在使用DropBox SDK,我不控制UIWebView,所以我不能添加我自己的代理。。。除非有办法这样做?是的,你是对的!。我们无法控制他们的委托方法。最新的Dropbox SDK提供了查找失败原因的功能。请下载最新的SDK并重试。有一个快乐的编码。哈哈,我从来没有想过寻找和网址。对于SDK来说,这是一种不常见且脆弱的表示取消的方式!我会尽快尝试这个,只要我有时间,并接受答案。非常感谢。工作起来很有魅力!我甚至在SDK源代码中找到了他们发送这个的地方。谢谢Haaa,我从来没有想过要查看和URL。对于SDK来说,这是一种不常见且脆弱的表示取消的方式!我会尽快尝试这个,只要我有时间,并接受答案。非常感谢。工作起来很有魅力!我甚至在SDK源代码中找到了他们发送这个的地方。谢谢