This page is an archive of iMAL's wiki that operated between 2012 and 2022. It documented projects, residencies and workshops mostly taking place at iMAL's Fablab.

Older & newer Fablab projects are now found at fablab.imal.org

Create a file in an OpenFrameworks iOS app and access it from your computer

... if your application saves for example images or text files that you'd like to get out of your iOS device.

 

First, as a reminder, that's how you typically write a local file in OpenFrameworks:

    ofFile file;
    file.open("myfile.txt", ofFile::WriteOnly, true);
    
    file << "poupoupidou" << endl;

To get the files stored in the sandboxed world of iOS, you must first make sure you write the file in the "documents" folder of your app.
You get the path of that folder with ofxiPhoneGetDocumentsDirectory(), so your file.open will be

 

file.open(ofxiPhoneGetDocumentsDirectory() + "myfile.txt", ofFile::WriteOnly, true);

 

 

The files locally stored on your iOS device can only be downloaded from the device through iTunes (yes, iTunes!). You must enable this feature in your ofxiphone-Info.plist file (in the openFrameworks folder of your project). Click on the (+) next to Information Property List and add "UIFileSharingEnabled". Xcode should automatically replace it by "Application supports iTunes file sharing", by default set as NO. Just set it to YES.

Once you have run your app on your device, start iTunes, select your device and go to the App tab. Scroll to the bottom.


and from there you can download your file!

Info

Difficulty: ●●○○○

Contributors:

Last updated: November 2012