Dropbox SDK - linkFromController:委托还是回调? [英] Dropbox SDK - linkFromController: delegate or callback?

查看:20
本文介绍了Dropbox SDK - linkFromController:委托还是回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用他们网站上提供的 SDK 将 Dropbox 添加到我的应用程序中.一旦 [[DBSession sharedSession] linkFromController:self]; 与帐户链接,是否有任何方法可以调用某些方法?

I'm adding Dropbox to my app using the SDK available on their site. Is there any way of calling some method once [[DBSession sharedSession] linkFromController:self]; links with an account?

基本上我想在应用尝试登录 Dropbox 后调用 [self.tableView reloadData].它甚至不需要区分登录是否成功.

Basically I'd like to call [self.tableView reloadData] once the app has tried to log in to Dropbox. It doesn't even need to discriminate between a successful or unsuccessful login.

推荐答案

Dropbox SDK 使用您的 AppDelegate 作为回调接收器.因此,当您调用 [[DBSession sharedSession] linkFromController:self]; 时,Dropbox SDK 无论如何都会调用您的 AppDelegate 的 – application:openURL:sourceApplication:annotation: 方法.

The Dropbox SDK uses your AppDelegate as a callback receiver. So when you have called [[DBSession sharedSession] linkFromController:self]; the Dropbox SDK will in any case call your AppDelegate's – application:openURL:sourceApplication:annotation: method.

所以在 AppDelegate 中,您可以通过 [[DBSession sharedSession] isLinked] 检查登录是否成功.不幸的是,您的 viewController 没有回调,因此您必须通过其他方式通知它(直接引用或发布通知).

So within the AppDelegate you can check by [[DBSession sharedSession] isLinked] if the login was successful or not. Unfortunately, there is no callback for your viewController, so you have to notify it by other means (direct reference or post a notification).

- (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;
}

由于 Apple 的政策存在问题,Dropbox 引入了这种相当奇怪的回调应用程序的方式.在旧版本的 SDK 中,会打开一个外部 Safari 页面来进行登录.Apple 在某个时间点不会接受此类应用程序.所以 Dropbox 的人引入了内部视图控制器登录,但保留 AppDelegate 作为结果的接收者.如果用户在他的设备上安装了 Dropbox 应用,登录将被定向到 Dropbox 应用,并且 AppDelegate 也会在返回时被调用.

This rather strange way of calling the app back was introduced by Dropbox due to an issue with Apple's policies. In older versions of the SDK, an external Safari page would have been opened to do the login. Apple would not accept such Apps at some point in time. So the Dropbox guys introduced the internal view controller login but kept the AppDelegate as the receiver of the results. If the user has the Dropbox App installed on his device, the login would be directed to the Dropbox App an also the AppDelegate will be called on return.

这篇关于Dropbox SDK - linkFromController:委托还是回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆