Kalpit Gajera
Kalpit Gajera

Reputation: 2525

Why can't app access another app's document folder?

We are trying to use inter-app communication for two application and trying to send the file path from one application to another application and the problem is that if i pass any text via sender application to receiver then it works well but if i try to pass the file document path then it doesn't works here is my code for sender

-(IBAction) openReceiverApp:(id)sender {
// Opens the Receiver app if installed, otherwise displays an error

UIApplication *ourApplication = [UIApplication sharedApplication];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory, @"ads.rtf"];
NSLog(@"filePath %@", filePath);
//  NSString *URLEncodedText = [self.textBox.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 NSString *URLEncodedText = [filePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *ourPath = [@"readtext://" stringByAppendingString:URLEncodedText];

NSLog(@"%@",ourPath);

NSURL *ourURL = [NSURL URLWithString:ourPath];
if ([ourApplication canOpenURL:ourURL]) {
    [ourApplication openURL:ourURL];
}
else {
    //Display error
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Receiver Not Found" message:@"The Receiver App is not installed. It must be installed to send text." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
}

In receiver side i have written this code

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
// Display text
UIAlertView *alertView;
NSString *text = [[url host]stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
alertView = [[UIAlertView alloc] initWithTitle:@"Text" message:text delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];

return YES;

am i going wrong anywhere?? Thanks in advance....

Upvotes: 1

Views: 1826

Answers (3)

PrabhakaranR
PrabhakaranR

Reputation: 13

I am not sure if you managed to work it out. But i thought of sharing this info which might be useful. Apple has released a new api in iOS8 to access documents outside your app’s sandbox.

Document Picker The document picker view controller (UIDocumentPickerViewController) grants users access to files outside your application’s sandbox. It is a simple mechanism for sharing documents between apps. It also enables more complex workflows, because users can edit a single document with multiple apps.

The document picker lets you access files from a number of document providers. For example, the iCloud document provider grants access to documents stored inside another app’s iCloud container. Third-party developers can provide additional document providers by using the Storage Provider extension.

For more information, see the Document Picker Programming Guide. (https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/DocumentPickerProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40014451)

Upvotes: 1

RobertL
RobertL

Reputation: 14874

I think there is something called a keychain access group that does what you want. I've never used it so I'm not real sure about it. Read about it and decide if it will work for you. Some comments I've seen suggest that it's hard to setup and test reliably.

You need to worry about what happens if keychain access needs to be renewed on a user's device after the two apps are installed. How can it be renewed is such a way that they continue to share access to each other's files?

Upvotes: 0

miho
miho

Reputation: 12085

The key word is Sandboxing. On iOS every app is sandboxed, which means it runs in it's own container and all data stored by the app should be secured against manipulation (read and write) of other apps.

It is impossible to access other apps Documents folder when the device is not jailbroken.

Upvotes: 3

Related Questions