0

我正在使用 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;

}

我在控制台上也显示了“应用程序链接成功”。

4

2 回答 2

1

There's a memory management related bug in the Dropbox iOS SDK. Here's a quote from my post on the Dropbox forums:

When the DBRestClient instance is declared as a local variable, it gets released at the end of the scope. It happens likely before actually it finishes exequting a request. Therefore, the connections are canceled and we can't receive callbacks. In order to avoid that DBRestClient shoud retain itself when it starts any request and release itself when it finishes it.

I discovered it when I had this issue: https://forums.dropbox.com/topic.php?id=105110

于 2013-09-07T11:30:43.793 回答
-1

what you can do is, first of all replace your that function(the function that you posted) by below function...(in Appdelegate.m file)

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

now In "YourViewController" class in which the file is present which you want to upload on dropbox..write below code in that file(.m file)

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

finally implement delegate method of 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);
 }

dont foreget to declare uploadToDropBox in .h file...

let me know it is working or not!!!

Happy Coding!!!!

于 2013-09-06T12:26:40.320 回答