开发者

How to save files onto an iPhone?

开发者 https://www.devze.com 2023-03-05 13:05 出处:网络
I have a question that most of you might find a little odd开发者_C百科. I am making an application for OS X, but I need it to write text files into an iPhone folder. I know the iPhone will have to be

I have a question that most of you might find a little odd开发者_C百科. I am making an application for OS X, but I need it to write text files into an iPhone folder. I know the iPhone will have to be connected to the computer, and I do not think that emailing will work.

I thought it would be as simple as finding a path to the iPhone while it was connected (such as /iPhone/Documents), but I cannot figure out what the path is. If anybody can tell me how to find the path, or can give me a link to some useful information, I will be very greatful

EDIT: although it was not the answer I wanted, I got what I needed. I think all of these answers gave me an equal amount of information, so I had a hard time choosing which answer to accept. I accepted the one that provided me with an alternative way to get the files onto the iPhone. Thanks for all of the help, everyone!


You will only be able to transfer files to and from your application using iTunes.

In order to get this to work your app must register for sharing documents in the Info.plist file by setting the UIFileSharingEnabled key to YES. When this is done your app will when installed and the device in connected show up on the "Application" tab in iTunes at the bottom. Highlight the app in the list to the left, and drag and drop files to the list on the right.

This way any file stored in the applications documents folder will be visible to iTunes, and any file copied to the device in iTunes will show up in the documents folder. You find the documents folder in your app like this:

NSArray* paths = NSSearchPathForDirectoriesInDomains(
                     NSDocumentDirectory, NSUserDomainMask, YES);
NSString* path = [paths lastObject];


That's not going to be possible. The iPhone connects over a proprietary(-ish) connection to iTunes, so you don't have any access into the iPhone's filesystem in your custom app. Besides which, apps in the iPhone have separate document folders so there isn't a single "documents" location on the device.

If you're writing your own iPhone app and want to support sharing documents with the Mac, you can either implement a Bonjour-based syncing service, sync via DropBox or iDisk, or use iTunes File Sharing. The options and trade-offs are well documented in this technote.


The iPhone doesn't have a mass storage mode, as Apple wants iTunes to be the ONLY method of transferring files to/from the iPhone. Maybe iTunes has an API for this that you can exploit, but otherwise the only way to get access to the file system in there is on jailbroken devices or via apps

0

精彩评论

暂无评论...
验证码 换一张
取 消