Search code examples
iphoneobjective-ciosipadnsfilemanager

iOS Writing Files


If a device is jailbroken, the file system is unlocked and open for you to see and modify. If I wanted to write an app that wrote a file to the /private/var/mobile/Library/Preferences/ folder, do I have to use a command other than [fileManager copyItemAtURL:fileTempPathURL toURL:filePathURL error:NULL]; ? I'm using this command, but it is not working... Thanks for your help!


Solution

  • If you're on a jailbroken device, you can write to any place in the system. You can do this in many different ways, from the C FILE pointer to all kinds of iOS Foundation methods, like the one you mentioned in your question.

    The only thing you'll have to mind is that your application has to be installed in the /Applications directory and not in the ~/Applications directory, what iTunes and Xcode will do by default. Only by putting them in that folder, along with the Apple base applications like MobileSafari, MobileMusicPlayer, etc. your app will launch from the springboard with those root privileges. You can put it in the /Applications folder through SSH.

    If you do not manually put your app in the root application folder and your app resides in its own subfolder in ~/Applications like normal App Store applications do, your app will launch in a sandbox. This sandbox will then prevent you from accessing any file outside your application's sandbox.