0

I develop an application that uses Bonjour. Each device stores some data in their Documents directory. Each device needs to access each other's data from their Documents directory. Is it possible?

  • @rmaddy : No, it's not. – rdurand Mar 06 '14 at 15:26
  • 2
    That's strange. I have an app in the store that let's a user transfer data between devices. The data that is transferred includes files stored within the app's sandbox. I guess I better tell my users to stop using that feature. :) – rmaddy Mar 06 '14 at 15:30

2 Answers2

1

As you questions stands: no. But what I think you are REALLY asking, is if an app can access data on another device. Of course, if you create an app than can communicate with other devices sharing the same app, your app can access data in the documents directory and offer them up to other devices.

SonGoku68 probably answered if another app could access it directly.

UPDATE

Here is an example on how you can access an image stored in Documents:

To store:

if ((imageFile) && ([imageFile respondsToSelector:@selector(getData)])) {
    NSData *fileData = imageFile.getData;
    NSString *imagePath = [NSString stringWithFormat:@"%@/%@.jpg", self.applicationDocumentsDirectoryString, @"fileNameWithoutExtension"];
    [fileData writeToFile:imagePath atomically:YES];
}

To get:

NSString *imagePath = [NSString stringWithFormat:@"%@/%@.jpg", self.applicationDocumentsDirectoryString, @"fileNameWithoutExtension"];
UIImage *img = [UIImage imageWithContentsOfFile:imagePath]; 

// Helper method to get Documents directory   
- (NSString *)applicationDocumentsDirectoryString {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    return [paths objectAtIndex:0];
}
Marius Waldal
  • 9,537
  • 4
  • 30
  • 44
  • Yes, I though user3388821 was asking about get data from others app. – Fran Martin Mar 06 '14 at 15:39
  • Maybe. I answered on what I think the user meant. Not what he/she wrote. Or rather; I answered both :-) – Marius Waldal Mar 06 '14 at 15:44
  • THanks for your response. Of course, I'm creating an app that can communicate with other devices sharing the same app. How can I get the data which is in the documents directory of other devices? Can anyone share the code? – user3388821 Mar 06 '14 at 16:07
  • This depends on what kind of data you have, and how it should be accessed. I will update my answer with an example. – Marius Waldal Mar 06 '14 at 16:12
  • I just have an array of strings in a device's documents folder. When I call a method from another device(using same wifi network), I should display this list of strings. Can you understand what i am telling? I think my English is poor. :-( – user3388821 Mar 06 '14 at 16:25
  • I guess the above code is to store and retrieve from the documents directory of same device. How can I get the data in another device? – user3388821 Mar 07 '14 at 05:01
  • Then we are back to the core; where we were unsure of what you meant. You can't directly get the data from another device. You would have to create a way for one device to contact another device with your app installed, and then ask that device to get the data from its Documents directory and give it to you. Direct access is impossible. This is called peer-to-peer connectivity. How this is done is a totally different (and very broad) question. Google for ios p2p etc – Marius Waldal Mar 07 '14 at 08:23
-1

You can´t access to the documents directory of other device. The sandbox of all apps is secured and you can´t access to it from other apps or device. For this you need to use Jailbreak in your devices

Fran Martin
  • 2,369
  • 22
  • 19
  • This isn't relevant to the OP's question. – rmaddy Mar 06 '14 at 15:33
  • I was speaking about to share info between your app and other different, maybe I didn´t undestand the question – Fran Martin Mar 06 '14 at 15:41
  • The question certainly could have been worded better but it seemed pretty clear the OP is talking about the specific app's Documents folder and not general access to the Documents folder of other apps. – rmaddy Mar 06 '14 at 15:43
  • Yes but if you create an app, you can do thousands way for to share info, because you create it, and for this reason I though he was talking about differents apps. :) – Fran Martin Mar 06 '14 at 15:48