Jos*_*osh 10 delegates dropbox ios
我正在使用其网站上提供的SDK将Dropbox添加到我的应用中.一旦[[DBSession sharedSession] linkFromController:self];与帐户链接,有没有办法调用某种方法?
基本上我想[self.tableView reloadData]在应用程序尝试登录Dropbox时调用.它甚至不需要区分成功或不成功的登录.
mar*_*cus 16
Dropbox SDK使用您的AppDelegate作为回调接收器.因此,当您调用[[DBSession sharedSession] linkFromController:self];Dropbox SDK时,无论如何都会调用AppDelegate的– application:openURL:sourceApplication:annotation:方法.
因此,在AppDelegate中,您可以检查[[DBSession sharedSession] isLinked]登录是否成功.遗憾的是,您的viewController没有回调,因此您必须通过其他方式(直接引用或发布通知)通知它.
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
// At this point you can start making API Calls. Login was successful
[self doSomething];
} else {
// Login was canceled/failed.
}
return YES;
}
// Add whatever other url handling code your app requires here
return NO;
}
Run Code Online (Sandbox Code Playgroud)
由于Apple的政策存在问题,Dropbox引入了这种相当奇怪的调用应用程序的方式.在旧版本的SDK中,将打开外部Safari页面以进行登录.Apple不会在某个时间点接受此类应用.所以Dropbox的人们引入了内部视图控制器登录,但是将AppDelegate作为结果的接收者.如果用户在其设备上安装了Dropbox App,则登录将被定向到Dropbox App,并且还将在返回时调用AppDelegate.
在App委托中添加:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([[DBSession sharedSession] handleOpenURL:url]) {
[[NSNotificationCenter defaultCenter]
postNotificationName:@"isDropboxLinked"
object:[NSNumber numberWithBool:[[DBSession sharedSession] isLinked]]];
return YES;
}
return NO;
}
Run Code Online (Sandbox Code Playgroud)
在你的自定义类:
- (void)viewDidLoad {
[super viewDidLoad];
//Add observer to see the changes
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isDropboxLinkedHandle:) name:@"isDropboxLinked" object:nil];
}
Run Code Online (Sandbox Code Playgroud)
和
- (void)isDropboxLinkedHandle:(id)sender
{
if ([[sender object] intValue]) {
//is linked.
}
else {
//is not linked
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5557 次 |
| 最近记录: |