Become a MacRumors Supporter for $25/year with no ads, private forums, and more!

iOS writeToURL Won't Write

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:

Wellington2k

macrumors regular
Original poster
Jun 4, 2011
131
0
There is?

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

Probably not, but bear with me. :eek:
 
Comment

dejo

Moderator emeritus
Sep 2, 2004
15,981
450
The Centennial State
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.
 
Comment

Wellington2k

macrumors regular
Original poster
Jun 4, 2011
131
0
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:
Comment

dejo

Moderator emeritus
Sep 2, 2004
15,981
450
The Centennial State
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).
 
Comment

Wellington2k

macrumors regular
Original poster
Jun 4, 2011
131
0
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!
 
Comment

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,011
4,885
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.");
}
 
Comment

Wellington2k

macrumors regular
Original poster
Jun 4, 2011
131
0
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:
Comment

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
writeToURL only works for file:// URLs. To write to an http:// URL you need to use NSURLConnection or something like that.
 
Comment

Wellington2k

macrumors regular
Original poster
Jun 4, 2011
131
0
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?
 
Comment

PhoneyDeveloper

macrumors 68040
Sep 2, 2008
3,114
93
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.
 
Comment

Wellington2k

macrumors regular
Original poster
Jun 4, 2011
131
0
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!
 
Comment
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.