我正在使用Dropbox Core API,当我想发送一个简单的[restClient loadMetadata:@"/"]
请求以便测试我的应用时,我既不会收到错误也不会成功回复。我用Charles嗅到了我的流量,看来Dropbox SDK没有发送任何请求。我的应用已关联。我已经复制粘贴了他们提供的代码。在这里。
-(BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication 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
DBRestClient *restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
restClient.delegate = self;
[restClient loadMetadata:@"/"];
}
return YES;
}
// Add whatever other url handling code your app requires here
return NO;
}
我也在控制台上显示“App linked successfully”。
答案 0 :(得分:1)
Dropbox iOS SDK中存在与内存管理相关的错误。 以下是我在Dropbox论坛上的帖子的引用:
当DBRestClient实例声明为局部变量时,它 在范围的最后发布。它可能在此之前发生 实际上它完成了执行请求。因此,连接 被取消,我们无法收到回电。为了避免这种情况 DBRestClient在启动任何请求时保持自己 完成后自我释放。
当我遇到这个问题时,我发现了它: https://forums.dropbox.com/topic.php?id=105110
答案 1 :(得分:-1)
你可以做的是,首先用下面的函数替换你的那个函数(你发布的函数)...(在Appdelegate.m文件中)
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
if ([[DBSession sharedSession] handleOpenURL:url])
{
if ([[DBSession sharedSession] isLinked])
{
NSLog(@"App linked successfully!");
// At this point you can start making API calls
NSArray *tmp=[self.navigationController viewControllers];
for(int i=0;i<[tmp count];i++){
if([[tmp objectAtIndex:i] isKindOfClass:[YourViewController class]]){//YourViewController is a class in which you want to implement dropbox sdk...
//[self.navigationController popToViewController:[tmp objectAtIndex:i] animated:YES];
[[tmp objectAtIndex:i] uploadToDropBox];
break;
}
}
}
return YES;
}
return NO;
}
现在在“YourViewController”类中,您要在dropbox上存在该文件。在该文件(.m文件)中的代码下面写入
-(void)uploadToDropBox
{
NSString *strzipname=[NSString stringWithFormat:@"%@_Document.zip",strname];
NSString *path = [DOCUMENTS_FOLDER stringByAppendingPathComponent:strzipname];
NSString *destDir = @"/";
restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];//DBRestClient *restClient; declare object in .h file
restClient.delegate = self;
[restClient uploadFile:strzipname toPath:destDir withParentRev:nil fromPath:path];//strzipname is a file name,"path" is path where that file is located
}
最后实现了dropbox的委托方法......
- (void)restClient:(DBRestClient*)client uploadedFile:(NSString*)destPath
from:(NSString*)srcPath metadata:(DBMetadata*)metadata {
NSLog(@"File uploaded successfully to path: %@", metadata.path);
}
- (void)restClient:(DBRestClient*)client uploadFileFailedWithError:(NSError*)error {
NSLog(@"File upload failed with error - %@", error);
}
不要忘记在.h文件中声明uploadToDropBox ...
让我知道它的工作与否!!!
快乐编码!!!!