writeToURL Won't Write

Discussion in 'iOS Programming' started by Wellington2k, Jan 30, 2012.

  1. Wellington2k, Jan 30, 2012
    Last edited: Jan 30, 2012

    Wellington2k macrumors regular

    Joined:
    Jun 4, 2011
    #1
    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?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    writeToURL: returns a BOOL. What is its value?
     
  3. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #3
    There is?

    Like this?
    Code:
    - (BOOL)writeToURL:URL atomically:(BOOL)atomically{
        return YES;
    }
    Probably not, but bear with me. :eek:
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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.
     
  5. Wellington2k, Jan 30, 2012
    Last edited: Jan 30, 2012

    Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #5
    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.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    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 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).
     
  7. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Why did you edit that post rather than posting a followup? Ugh! I'm out. But I want to wish you luck in figuring it all out.
     
  9. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #9
    I got the error!
     
  10. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #10
    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.");
    }
     
  11. Wellington2k, Jan 30, 2012
    Last edited: Jan 30, 2012

    Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #11
    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.
     
  12. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #12
    writeToURL only works for file:// URLs. To write to an http:// URL you need to use NSURLConnection or something like that.
     
  13. Wellington2k, Jan 31, 2012
    Last edited: Jan 31, 2012

    Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #13
    It wouldn't work anyway.

    Dropbox is read-only.
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  15. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
  16. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #16
    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?
     
  17. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #17
    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.
     
  18. Wellington2k, Jan 31, 2012
    Last edited: Jan 31, 2012

    Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #18
    I'm still at downloading.



    What path should I do?
     
  19. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #19
    Read about the REST API. That's how you communicate with dropbox.
     
  20. Wellington2k, Feb 1, 2012
    Last edited: Feb 1, 2012

    Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #20
    O.K.

    I did the MetaDtata and it found my file.
     
  21. Wellington2k, Feb 1, 2012
    Last edited: Feb 1, 2012

    Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
  22. Wellington2k thread starter macrumors regular

    Joined:
    Jun 4, 2011
    #22
    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!
     

Share This Page