Dropbox文档默认解释了身份验证的响应被触发到Appdelegate.m中 如何使我自己班级的代表同样开火?
- (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
}
return YES;
}
// Add whatever other url handling code your app requires here
return NO;
}
答案 0 :(得分:0)
在信息plist网址类型 - >在url方案中只需添加db-YourAppKey即可调用此方法。
此方法将自动调用。我希望你已经从dropbox开发者网站创建了app并获得了appKey和appSecret。在app delegate NSString * appKey = @“”;
中使用此代码
NSString* appSecret = @"";
NSString *root = kDBRootDropbox;
NSString* errorMsg = nil;
if ([appKey rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location != NSNotFound) {
errorMsg = @"Make sure you set the app key correctly in DBRouletteAppDelegate.m";
} else if ([appSecret rangeOfCharacterFromSet:[[NSCharacterSet alphanumericCharacterSet] invertedSet]].location != NSNotFound) {
errorMsg = @"Make sure you set the app secret correctly in DBRouletteAppDelegate.m";
} else if ([root length] == 0) {
errorMsg = @"Set your root to use either App Folder of full Dropbox";
} else {
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
NSData *plistData = [NSData dataWithContentsOfFile:plistPath];
NSDictionary *loadedPlist =
[NSPropertyListSerialization
propertyListFromData:plistData mutabilityOption:0 format:NULL errorDescription:NULL];
NSString *scheme = [[[[loadedPlist objectForKey:@"CFBundleURLTypes"] objectAtIndex:0] objectForKey:@"CFBundleURLSchemes"] objectAtIndex:0];
if ([scheme isEqual:@"db-APP_KEY"]) {
errorMsg = @"Set your URL scheme correctly in DBRoulette-Info.plist";
}
}
DBSession* session =
[[DBSession alloc] initWithAppKey:appKey appSecret:appSecret root:root];
session.delegate = self; // DBSessionDelegate methods allow you to handle re-authenticating
[DBSession setSharedSession:session];
[DBRequest setNetworkRequestDelegate:self];
// [[DBSession sharedSession]unlinkAll];
if ([[DBSession sharedSession] isLinked])
{
isAccountForDropBox = YES;
}
else{
isAccountForDropBox = NO;
}
//使用此后,打开的URL会自动调用。
答案 1 :(得分:0)
这些方法只在AppDelegate.m中响应,你不能在它之外使用它。 要在ViewController或任何类中使用,您应该使用帖子后通知
- (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!");
// Post Notify here
[[NSNotificationCenter defaultCenter] postNotificationName:@"applicationDidLinkWithDropbox" object:self];
}
return YES;
}
// Add whatever other url handling code your app requires here
return NO;
}
然后在您的课程中,在ViewController中接收此通知,例如:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(dropBoxDidLink:)
name:@"applicationDidLinkWithDropbox"
object:nil];
}
- (void) dropBoxDidLink:(NSNotification *)notification {
if ([[notification name] isEqualToString:@"applicationDidLinkWithDropbox"]) {
//Handle your task here
}
}