简体   繁体   中英

Dropbox iOS SDK - Requests are not sent

I am using dropbox Core API and when I want to send a simple [restClient loadMetadata:@"/"] request in order to test my app neither do I receive an error nor a successful response. I sniffed my traffic with Charles and it appears that Dropbox SDK does not send any request. My app is linked. I have copy-pasted the code they provided. Here it is.

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

}

I have got "App linked successfully" displayed on the console as well.

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

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!!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM