Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Wellington2k

macrumors regular
Original poster
Jun 4, 2011
131
0
Hello.

I want to write on a simple text file on dropbox.

But this code won't work:

Code:
[xstring writeToURL:URL atomically:NO encoding:NSUTF8StringEncoding error:NULL];

And yes it allows reading and writing.

Code:
URL = [[NSURL alloc] initWithString:@"http://dl.dropbox.com/u/50204897/myfile.txt"];

Any help?
 
Last edited:
There is?

Like this?
Code:
- (BOOL)writeToURL:URL atomically:(BOOL)atomically{
    return YES;
}

Probably not, but bear with me. :eek:
 
So, I take it you're not familiar with the concept of a return value from a method call. My advice: Step back from the real coding; go learn the fundamentals of Objective-C programming.
 
I got something!

Code:
    if (![xstring writeToURL:URL atomically:NO encoding:NSUTF8StringEncoding error:NULL]) {
        NSLog(@"ERROR!!!");
    }

It does give me the NSLog.

So it's not writing at all.
 
Last edited:
I know about return values.
Then why are you writing a new method (like in this post) instead of simply capturing the return value that your method call sends back?

Help me by showing me.

Help us to confirm your understanding of return values by showing us how you would capture and output the return value of writeToURL: (or any method that returns a value, for that matter).
 
Error Domain=NSCocoaErrorDomain Code=518 "The operation couldn’t be completed. (Cocoa error 518.)" UserInfo=0x6a88210 {NSURL=http://dl.dropbox.com/u/50204897/myfile.txt}

I got the error!
 
I got something!

Code:
    if (![xstring writeToURL:URL atomically:NO encoding:NSUTF8StringEncoding error:NULL]) {
        NSLog(@"ERROR!!!");
    }

It does give me the NSLog.

So it's not writing at all.

Google tells me you need permission to writeToURL?

IDK, I've never tried, I'm not even quite sure what the method does.

Maybe you should let us know what URL is?

Regarding what dejo wanted, he probably wanted something along the lines of

Code:
bool okay = [xstring writeToURL:URL atomically:NO encoding:NSUTF8StringEncoding error:NULL];
if (!okay)
{
 NSLog(@"Error writing to URL.");
}
 
I just got a DUH moment.

Yep it gave me an error.

But I believe that Dropbox has read-only for public.

And you can't change it. :(

Oh well, thanks for trying.
 
Last edited:
writeToURL only works for file:// URLs. To write to an http:// URL you need to use NSURLConnection or something like that.
 
Alright, I successfully got it to authenticate.

Now it connects!

But how to I write to it?

There is no URL. Do I have to download and re-upload?
 
Look at the REST API in the SDK docs. That's how you upload a file and do various other things.

You can use NSURLConnection or ASIHTTPRequest to POST a file to the REST API.
 
IT WORKED!

Thanks so much for your help!

Let me just get all the code together so I can post my solution!

Thanks for your time!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.