initWithContentsOfURL question

Discussion in 'iOS Programming' started by kage777, Jan 2, 2010.

  1. kage777 macrumors newbie

    Joined:
    Feb 24, 2008
    #1
    Hi,

    I'm am pretty new to iphone developing and am trying to write an app that first gets the contents of a file off of a shared folder on a windows machine over a wifi connection.

    I was wondering if I could tell me if I could use initWithContentsOfURL to do this or not? and if not is there a way to do this?

    thanks
     
  2. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #2
    That method returns to a string what ever is posted by by the http url.
     
  3. Saladinos macrumors 68000

    Saladinos

    Joined:
    Feb 26, 2008
    #3
    I doubt it will work if its a Windows machine, but I haven't tried it myself.
     
  4. MacDonaldsd macrumors 65816

    MacDonaldsd

    Joined:
    Sep 8, 2005
    Location:
    London , UK
    #4
    This will only work if you can access the given file through a URL. I doubt you can though.
     
  5. kage777 thread starter macrumors newbie

    Joined:
    Feb 24, 2008
    #5
    after doing some more research it seems I can't use this, but instead need a samba client for the iphone, but can't seem find one.

    there are a couple of apps that seem like they can do this (data case, filesync),
    so it seems like it should be possible.

    but I can't figure out how to do it....any ideas?
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    If you install a web server on the Windows machine, you should be able to (once configured correctly) access that file via URL.
     
  7. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
    #7
    Wow, I never knew about initWithURL until I read this. I can find thousands of useful ways to use it and interact with my website. I don't know about web servers or files (sorry to disappoint) but I just want to say how helpful this post has been even if it wasn't meant to be.
     
  8. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #8
    Actually it's a bad idea to use initWithContentsOfURL. It is a synchronous call. If the network isn't working well it may take 30 seconds to time out. And the watchdog will kill your app if it doesn't do anything for 20 seconds.

    Use the asynchronous method with NSURLConnection instead.

    Oh and by the way it's simple to set up your Mac's web sharing to allow your app running on the device to download files directly from your Mac. I do this for testing.
     
  9. drf1229 macrumors regular

    drf1229

    Joined:
    Jun 22, 2009
  10. kage777 thread starter macrumors newbie

    Joined:
    Feb 24, 2008
    #10
    You mentioned it is easy to set up a Mac to download directly from it, but can it be done without an internet connection? What if I just have a closed network between the machine and the phone?

    Also can it be done on a Windows machine, as the file I need to get off only is made from a program that is windows only?

    thanks for the help
     
  11. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #11
    You can connect from your device to your Mac via WiFi. No internet connection is required.

    All you need to do is turn on Web Sharing on the Mac. Put your files that you want to download in the ~/Sites folder. When you turn on web sharing you'll see the URL for 'your personal website.' Just use NSURLConnection to download the files from that URL.

    In theory this can also be done on Windows. There is a web server called IIS that is available for Windows. If you use that you should be able to download files served by that web server from a Windows machine. I haven't tried this with Windows but it should work fine.
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    Apache is also available for Windows.
     

Share This Page