Jonathan
Jonathan

Reputation: 614

iOS Move My Apps Saved File in Documents Dir to Another Computer

I am trying to figure out how to get a file saved (csv file) in my iOS app documents directory moved onto another computer. More specifically a windows server. Right now the app is in testing on an ipad. I don't know if I can access those files with another app, or if I could save the files somewhere else on the ipad where I can access it.

Ideally I would want to do the transfer over wifi, but I am open to other options.

Upvotes: 2

Views: 192

Answers (2)

Abhi Beckert
Abhi Beckert

Reputation: 33379

Send the file over HTTP:

NSURL *url = [NSURL URLWithString:@"http://example.com/upload-file"];
NSData *fileData = [NSData dataWithContentsOfURL:urlToFile];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:fileData];

NSHTTPURLResponse *urlResponse = nil;
NSError *error = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];

You'll probably want to do that on a background thread, and check the response data for some kind of confirmation message that the file was received. I usually have the server respond with the size of the file that was received. Then the client can compare that size to the amount of data that was supposed to have been sent.

On the server end, you want to read the POST data to access the file contents. I'm not sure how to do this on a windows server.

Upvotes: 1

Robert Scott
Robert Scott

Reputation: 56

You can enable File Sharing in your info.plist file for the app. This will give you manual read/write access to the app's document directory. Here is the raw XML:

<key>UIFileSharingEnabled</key>
<true/>

Then when the iOS device is connected to a computer running iTunes, the app's document directory will be accessible as described here.

Upvotes: 4

Related Questions