Take Your Search Game to the Next Level with Dropbox Dash 🚀✨ Curious how it works? Ask us here!
Forum Discussion
purringpigeon
9 years agoExplorer | Level 4
Help migrating from v1 to v2 Objective C
Hello,
I am not very familiar with Dropbox API, though I got version 1 working just fine on my app. But I am not really following the path from V1 to V2 all that well.
I am attempting to...
purringpigeon
9 years agoExplorer | Level 4
Thanks - that makes sense. I was trying to scale back my dropbox controller to post - which I will if I can make sense of it.
Here is the basics of what I have:
- (void)viewDidLoad{ [super viewDidLoad]; } - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // Do any additional setup after loading the view. // Reference after programmatic auth flow self.restClient = [DropboxClientsManager authorizedClient]; if (!networkLost) { [self checkForBackups]; } } - (void) checkForBackups { //Determine if backup exists if(self.restClient != nil ) { _loadingView = [LoadingView loadingViewInView:[self.view.window.subviews objectAtIndex:0] withMessage:@"Checking for existing backup...."]; [[self.restClient.filesRoutes getMetadata:@""]response:^(DBFILESMetadata * _Nullable result, DBFILESGetMetadataError * _Nullable routeError, DBRequestError * _Nullable error) { if(result != nil){ if ([result isKindOfClass:[DBFILESFolderMetadata class]]){ //NewObj* pNew = (NewObj*)oldObj; DBFILESFolderMetadata * meta = (DBFILESFolderMetadata *)result; files = [[NSMutableArray alloc]init]; } [_loadingView removeView]; //check to see if there is a backup to restore /* for (DBMetadata *file in files) { if([file.path isEqualToString:@"/ServiceReport.sqlite"]){ hasSQLBackup = YES; } if([file.path isEqualToString:@"/ServiceReport.sqlite-shm"]){ hasSHMBackup = YES; } if([file.path isEqualToString:@"/ServiceReport.sqlite-wal"]){ hasWALBackup = YES; } } */ } }]; } }
This call seems to crash the app - but I get no error. Then when I run it again, it wants to link the account again.
purringpigeon
9 years agoExplorer | Level 4
This I think is the basics of what I am attempting - hopefully it makes sense. I am simply uploading the SQLITE db and files.
#import "AppDelegate.h" #import "DropBoxViewController.h" #import "LoadingView.h" #import "ConvertNSDateToString.h" //#import <DropboxSDK/DropboxSDK.h> #import <ObjectiveDropboxOfficial/ObjectiveDropboxOfficial.h> @interface DropBoxViewController () <UIAlertViewDelegate> //@property (nonatomic, strong) DBRestClient *restClient; @property (nonatomic, strong) DropboxClient *restClient; @property (nonatomic, weak) LoadingView *loadingView; @end NSMutableArray *files = nil; @implementation DropBoxViewController - (void)viewDidLoad{ [super viewDidLoad]; } - (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.restClient = [DropboxClientsManager authorizedClient]; //self.restClient.delegate = self; if (!networkLost) { [self checkForBackups]; } } - (void) checkForBackups { //Determine if backup exists if([DropboxClientsManager authorizedClient] != nil ) { DropboxClient *client = [DropboxClientsManager authorizedClient]; [[client.filesRoutes getMetadata:@""]response:^(DBFILESMetadata * _Nullable result, DBFILESGetMetadataError * _Nullable routeError, DBRequestError * _Nullable error) { //NOT SURE HOW TO CHECK THIS… //USED to be loadedMetadata }]; [_loadingView removeView]; } } - (IBAction)linkToDropBox:(id)sender { [DropboxClientsManager authorizeFromController:[UIApplication sharedApplication] controller:self openURL:^(NSURL *url) { [[UIApplication sharedApplication] openURL:url]; } browserAuth:YES]; [self checkForBackups]; } //TODO - FIX THIS COMMENT /* - (void)restClient:(DBRestClient *)client loadedMetadata:(DBMetadata *)metadata { if (metadata.isDirectory) { files = [[NSMutableArray alloc]init]; for (DBMetadata *file in metadata.contents) { [files addObject:file]; } } //check to see if there is a backup to restore for (DBMetadata *file in files) { if([file.path isEqualToString:@"/ServiceReport.sqlite"]){ hasSQLBackup = YES; } } [self displayDropboxButtons]; } */ - (void) startBackUp { _loadingView = [LoadingView loadingViewInView:[self.view.window.subviews objectAtIndex:0] withMessage:@"Backing up data to Dropbox...."]; [self uploadFileToDropbox:@"ServiceReport.sqlite"]; } - (void) uploadFileToDropbox:(NSString*)fileName { NSString *rev = nil; //check to see if there is a backup to to overwrite //TODO - FIX THIS COMMENT /* for (DBMetadata *file in files) { if([file.filename isEqualToString:fileName]){ rev = file.rev; break; } } NSString *localDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; NSString *dbPath = [localDir stringByAppendingPathComponent:fileName]; NSString *destDir = @"/"; [self.restClient uploadFile:fileName toPath:destDir withParentRev:rev fromPath:dbPath]; */ } //TODO - FIX THIS COMMENT /* - (void)restClient:(DBRestClient *)client uploadedFile:(NSString *)destPath from:(NSString *)srcPath metadata:(DBMetadata *)metadata { NSLog(@"File uploaded successfully to path: %@", metadata.path); } */ //This is the call to query for the file to restore and its call backs //TODO - FIX THIS COMMENT /* - (void) startTheRestoreProcess { _loadingView = [LoadingView loadingViewInView:[self.view.window.subviews objectAtIndex:0] withMessage:@"Restoring from backup...."]; //create the local path NSString *localDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; NSString *localPath = [localDir stringByAppendingPathComponent:@"ServiceReport.bak"]; [self.restClient loadFile:@"/ServiceReport.sqlite" intoPath:localPath]; } - (void)restClient:(DBRestClient *)client loadedFile:(NSString *)localPath contentType:(NSString *)contentType metadata:(DBMetadata *)metadata { NSLog(@"File loaded into path: %@", localPath); } */ /* This is the error handling form Dropbox Callbacks */ //TODO - FIX THIS COMMENT /* - (void)restClient:(DBRestClient *)client loadMetadataFailedWithError:(NSError *)error { NSLog(@"Error loading metadata: %@", error); [self showErrorMessage:error]; } - (void)restClient:(DBRestClient *)client uploadFileFailedWithError:(NSError *)error { NSLog(@"File upload failed with error: %@", error); [self showErrorMessage:error]; } - (void)restClient:(DBRestClient *)client loadFileFailedWithError:(NSError *)error { if (error.code == 404) { NSLog(@"Your file was not found"); [self showErrorMessage:error]; }else if (error.code == 401) { NSLog(@"Your account is no longer authorized."); [self showAccountNotLinked]; }else { NSLog(@"NSError ** : %@", [error userInfo]); [self showErrorMessage:error]; } } */ - (void) relinkToDropbox { /* [[DBSession sharedSession] unlinkAll]; */ [DropboxClientsManager unlinkClients]; _restClient = nil; [self linkToDropBox:nil]; } @end
- Greg-DB9 years ago
Dropbox Community Moderator
The app shouldn't be crashing without some sort of error. Can you double check the console in Xcode?
- purringpigeon9 years agoExplorer | Level 4
It's weird - The only error I show is the one noted above.
This always returns nil
self.restClient = [DropboxClientsManager authorizedClient];
- Greg-DB9 years ago
Dropbox Community Moderator
If authorizedClient is nil, that would be why your app doesn't seem to "remember" the user. That's presumably related to the crash you're getting. Perhaps the app is crashing before the access token is being stored. Can you step through in the debugger to at least see where the crash is occurring?
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,011 PostsLatest Activity: 2 years ago
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!