如果有人遇到這種並卡在巴拉的答案,那是因爲這個方法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組件字的「取消」,如果它發現你剛剛發送的地方適用於您的應用程序告訴它的用戶取消了進程的通知。
觀察者代碼爲您的通知發佈,把這個地方放在你想檢測上面發佈的通知。
下面這爲我工作的代碼,我已經使用
[[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*/}
- (BOOL)應用:(UIApplication的*)應用handleOpenURL:(NSURL *)網址{ 如果([[DBSession sharedSession] handleOpenURL:URL]){ 如果([[DBSession sharedSession] isLinked]){ ALog(@「App linked successfully!」); //此時您可以開始進行API調用 } return YES; } \t return NO; } – Bala
我沒有找到如何識別失敗的原因..但[UIWebViewDelegate的webView:didFailLoadWithError:](http://developer.apple.com/library/ios/documentation/uikit/reference/UIWebViewDelegate_Protocol/Reference/ Reference.html#// apple_ref/doc/uid/TP40006951-CH3-SW5)應該可以幫助你找到我認爲是的原因.. – Bala
@Bala我使用DropBox SDK,我不控制UIWebView,所以我不能添加我自己的委託...除非有辦法這樣做? –