You are just trying to send an NSString thats with you get en error. You need to save the pdf or txt file to disk and then pass the path to that file to dropbox.
__________________ SQLed - Your Database Manager on the go
pdfString is coming back nil though. Am I on the right path here or how should I store the pdfData into a string? Or should it be stored into a string to store it into the path?
Changed one line of code and now I'm getting this error
Code:
[WARNING] DropboxSDK: error making request to /1/files_put/sandbox/test.pdf - Error Domain=dropbox.com Code=502 "The operation couldn’t be completed. (dropbox.com error 502.)"
Not sure what I was getting that error but I commented out a couple of lines I wasn't using and removed all break points. Ran the app again and it worked!
My file was uploaded successfully to my Dropbox.
Just need to add in a HUD and a few other things!
Thank you so much for your help. I appreciate it a lot!
If your using the new Dropbox sdk which does the login in the Dropbox app or in safari you could create a protocol in your apps delegate and then connect your viewcontroller to that.
Here is what I do
Code:
#MyAppDelegate.h
@protocol DropBoxLoginDelegate <NSObject>
- (void)logedIn;
@end
@interface MyAppDelegate : NSObject{
...
...
id<DropBoxLoginDelegate>_dropBoxDelegate;
}
...
...
@property (assign) id<DropBoxLoginDelegate> dropBoxDelegate;
#MyAppDelegate.m
@implementation MyAppDelegate
@synthesize dropBoxDelegate = _dropBoxDelegate;
...
...
- (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!");
[self.dropBoxDelegate logedIn];
// At this point you can start making API calls
}
return YES;
}
MyViewController.h
@interface basedbDetailedViewController : UITableViewController<DropBoxLoginDelegate>{
...
...
- (void)viewDidLoad
{
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.dropBoxDelegate = self;
...
...
}
- (void)logedIn{
//Here goes your code for uploading the file
}
__________________ SQLed - Your Database Manager on the go
I built a sample app to make sure this works and it does. Works just how I want it too.
I have added this code into my app that will go live and Dropbox is not fully working.
I was able to open Dropbox, log in and allow Dropbox to use this app. A new folder was made in my Dropbox account. But my file is not being uploaded at all.
I don't even think the restClient is being called. I've set some breakpoints and it just gets skipped over. Any thoughts on why this would happen?
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([[DBSession sharedSession] handleOpenURL:url]) {
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"App linked successfully!");
[self.dropBoxDelegate loggedIn];
// At this point you can start making API calls
}
return YES;
}
// Add whatever other url handling code your app requires here
return NO;
}
When the app launches users can input information, etc. then can they can go to the next view (this is done by presentModalViewController). Here they have the sharing options, one is Dropbox.
The app still only works if I remove it and install it again. The Dropbox code works perfectly. But if I close the app and re-launch it, the Dropbox code is not getting called.
I think I got it. How does the user select the Dropbox upload? From a button, actionsheet ? Because you are just uploading when the user links the app to Dropbox. Once the app is linked to Dropbox this
Code:
if ([[DBSession sharedSession] isLinked]) {
NSLog(@"App linked successfully!");
[self.dropBoxDelegate loggedIn];
// At this point you can start making API calls
}
is not called.
So when lets say your button or actionsheet button is clicked you should check if the app is linked or not. If its not it will do what you do now but if its linked simply call
Code:
[self loggedIn];
__________________ SQLed - Your Database Manager on the go