Writing files to Documents Dir

Discussion in 'iOS Programming' started by xArtx, Nov 3, 2012.

  1. xArtx macrumors 6502a

    Mar 30, 2012
    Hi Guys,
    I've been using a Windows program like iPhone Browser to copy files over
    to an application's documents directory, but it occurs to me that you can't
    access application folders if the device is not jailbroken.

    Is the standard way to copy files over just once for an initial setup
    if the files are not already present to copy them from the main bundle to the
    Documents directory at run time?
    Cheers, Art.
  2. truehybridx macrumors member

    Dec 6, 2010
    i believe in 5.x you could using iExplorer without a jailbreak, but in 6.x they locked that out from USB too...

    They want you to use iTunes if the app supports it im afraid :(
  3. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    I have used iExplorer too for this.

    But like you said you yourself is checking on startup if a specific file is there, if not, then copy it over :) Also be careful of WHERE you put it if it's an app going on the appstore, you have to make sure it's not backed up to iCloud for no reason (if you put it in the DOcuments folder, it automatically goes there & will get your app rejected).

    Greetings, noxx
  4. xArtx thread starter macrumors 6502a

    Mar 30, 2012
    Thanks :)

    Is there somewhere you can store and retrieve stuff that is accessible with
    a PC, but without iTunes?

    I was using an iPad program to sort a daily list of stock to replenish according to the locations the stock is kept.
    Moving the files has now become difficult.

    Or, is is possible to have one of the email file downloaders put the source
    file somewhere accessible by my program and have it emailed back?
    I have an app called quick Office that can mail attachments, but I think I'd need a jailbroken iPad to use ifile to get the file into Quick Office's documents directory so it could be sent.

    Basically, any way of getting a small text file in and back out of an iPad would be nice.
    Any ideas?
  5. xArtx thread starter macrumors 6502a

    Mar 30, 2012
    I've implemented the sample that sends email with attachment from within the app,
    so that part is sorted.

    Now it's just a matter of getting the source file into it.
  6. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    I have no idea what you're trying to achieve :) You have multiple apps wanting to work together with sending files & then via mail or via pc?
    I don't understand 100%, so I can 't answer your question easily :)
  7. xArtx thread starter macrumors 6502a

    Mar 30, 2012
    For starters I registered as a developer to program personally.
    I have little interest in the app store (so no rules apply to what I do in the app),
    but Apple makes no provision for personal programming.

    The particular app receives a file from a work computer (formally via iexplorer straight into the app's documents directory).
    The file from the work computer is a list of stock records arranged in order of a field that is useless to me.
    The app sorts the file records in order of stock location making it much quicker to retrieve with a forklift, and then that file used to be copied back out of the ipad (again with iexplorer). I copy the file back to the computer to print it in the newly sorted order. This gives me more time to smoke & muck around at work.

    That all went to hell when my jailbroken iPad clapped out, and I had to update to 6.0.1 not jailbroken.

    So I have Apple's email sample implemented to send the file back out of the iPad,
    but currently the only way I have to get it into the iPad in the first place is
    to compile it with the app's main bundle which required my computer at home.

    Basically, I'm looking for the easiest beginner way to get a file into the app's documents directory.
    Cheers :)
  8. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    The easiest way is with iTunes file sharing. Apple's sample code DocInteraction shows how to do this.

    You could also email it to yourself. On the device you could then use OpenIn from mail and have the file copied into your app's sandbox.

    You can put the file onto a web server and then simply download it into your app from the web server. You can do this with web sharing from a Mac. There's something similar on Windows.

    You could also build a web service that runs on your desktop computer and serves the file. Probably not easy.

    Embedded web server in the app allows you to upload a file into the app. There are a number of open-source simple web servers that you can embed in an iOS app.

    There are many apps that implement these features and if you get your document onto the device then you can use Open In, UIDocumentInteractionController to transfer the file to your app.

    iTunes file sharing or email are the simplest of these options.
  9. xArtx thread starter macrumors 6502a

    Mar 30, 2012
    That's comprehensive, and I feel I should reply, but haven't given it time
    to make progress. I have populated the email attachment to send out.

    With regard to the file being delivered to the device, I'll have to forget about
    iTunes being installed on the work computers.
    They can send emails though, and Openin sounds like the way to go to receive the file.

    Is there a well known tutorial other then this:http://www.raywenderlich.com/1980/how-to-import-and-export-app-data-via-email-in-your-ios-app

    I haven't followed it yet, but when it comes to it, I'd rather know now if
    there is any more "generally accepted" example.
    Thanks, Art.
  10. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Dunno about other tutorials. Apple's DocInteraction sample code is an example I use a lot.
  11. xArtx thread starter macrumors 6502a

    Mar 30, 2012
    Docinteration appears to be just for iTunes file sharing.

    Didn't see a sample for the open in feature,
    and couldn't even figure out how to edit my plist.info file
    with the keys in the tutorial.

    I set up a paste box, so I can just cut & paste for now since
    the report is a plain text file, it works.
    I can email myself the file and open it with QuickOffice,
    and then copy the text and paste it into my app.

    Obviously no good if the source file wasn't text, but ok for now.
  12. troop231 macrumors 603

    Jan 20, 2010
    Are you trying to export a comma seperated .txt file or something similar? I may be able to help you with this, as I have written a way to export something similar using the built in iOS email composer.
  13. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Dicinteraction has four files built in and you can add more. If you choose the jpeg file, for instance, then tap near the top of the screen you can Open In any other app that registers that it can accept jpeg files. It uses UIDocumentInteractionController for this. If your app registers for a file this sample app will send it to your app.
  14. xArtx thread starter macrumors 6502a

    Mar 30, 2012
    Oh man, I should be embarrassed about feeling proud for auto pasting
    the clipboard right where I want it at application launch.
    I paste straight to a text view, and read from there to a c char array,
    then hide the iOS text view.
    Very clean don't you think? but yes, the open in functionality would make
    the current setup look silly :D

    @ troop231,
    I have taken care of creating and sending the csv file already.
    Had to learn how to number the pages in the footer, and show
    the title row for every printed page in MS Excell.

Share This Page