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

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

问题描述

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



基本上,一旦应用程序尝试登录到Dropbox,我想调用 [self.tableView reloadData] 。它不需要区分成功或不成功的登录。

解决方案

Dropbox SDK使用您的AppDelegate作为回调接收器。所以当你调用 [[DBSession sharedSession] linkFromController:self]; Dropbox SDK将无论如何调用
你的AppDelegate的 - 应用程序:openURL:sourceApplication:annotation:方法。



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

 (BOOL)应用程序:(UIApplication *)应用程序openURL :( NSURL *)url sourceApplication:(NSString *)sourceApplication注释:(id)注释{
if([[DBSession sharedSession] handleOpenURL:url]){
if([[DBSession sharedSession] isLinked]){
//此时可以开始进行API调用。登录成功
[self doSomething];
} else {
//登录已取消/失败。
}
return YES;
}
//添加您的应用程序需要的其他任何其他url处理代码
return NO;
}

由Dropbox引入的这个非常奇怪的调用应用程序的方法是由于问题与苹果的政策。在旧版本的SDK中,外部Safari页面将被打开以进行登录。苹果在某个时候不会接受这样的应用程序。所以Dropbox的家伙介绍了内部的视图控制器登录,但保持AppDelegate作为结果的接收者。如果用户在他的设备上安装了Dropbox App,则登录将被转发到Dropbox App,AppDelegate也将在返回时被调用。


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?

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.

解决方案

The Dropbox SDK uses your AppDelegate as callback reciever. 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.

So within the AppDelegate you can check by [[DBSession sharedSession] isLinked] if the login was successful or not. Unfortunately there is not 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;
}

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天全站免登陆