1

Summary (iOS 8, Xcode 6.4)

First question:- Can i share my app's Documents Directory's data with my other app?

If Yes, I've seen many questions related to this; Move data/images between two iOS apps using custom URL handler, http://code.tutsplus.com/tutorials/ios-sdk-working-with-url-schemes--mobile-6629

But I found that these example only send text or URLs. Then I tried myself as below:

NSString* path = [NSString stringWithFormat:@"MY_URL_SCHEME://"];
NSURL* url = [NSURL URLWithString:path];
if([[UIApplication sharedApplication]canOpenURL:url]) {
    [[UIApplication sharedApplication]openURL:url];
}

The above code works well to open my other app. But when I try like below, I can't open my other app.

NSArray* mainPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *sourcePath = [mainPath objectAtIndex:0];
NSString* path = [NSString stringWithFormat:@"MY_URL_SCHEME://%@",sourcePath];
NSURL* url = [NSURL fileURLWithPath:path isDirectory:YES];
if([[UIApplication sharedApplication]canOpenURL:url]) {
    [[UIApplication sharedApplication]openURL:url];
}

So, please help me, what am I missing?
EDIT:-
i forgot to mention that,iOS7 support is important in my App.so, i think extension might not work.

Community
  • 1
  • 1
Vatsal Shukla
  • 1,274
  • 12
  • 25
  • 1
    Do you **really** need to use a URL scheme for this? It sounds like it might be better as an extension. See https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/index.html#//apple_ref/doc/uid/TP40014214-CH20-SW1 – Steve Wilford Sep 21 '15 at 13:44
  • @SteveWilford, actually,i only want to send some data from one app to another. the way doesn't matter. by the way, let me try your suggestion. – Vatsal Shukla Sep 21 '15 at 13:50
  • 1
    If you control both apps and they are setup according to the requirements you can create an App Group that will allow you to share a common file system. See [this question](http://stackoverflow.com/questions/24015506/communicating-and-persisting-data-between-apps-with-app-groups), [this blog](http://www.atomicbird.com/blog/sharing-with-app-extensions), and the [Apple Docs](https://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/EnablingAppSandbox.html#//apple_ref/doc/uid/TP40011195-CH4-SW19) – Steve Wilford Sep 21 '15 at 13:55
  • I you just want to send some data, you can use base64 encoded string for that file/data – Johnykutty Sep 21 '15 at 14:01

2 Answers2

0

Use NSUserDefaults with app group to share the data between apps

NSUserDefaults *defaults=[[NSUserDefaults 
alloc]initWithSuiteName:@"app group name"];
[defaults setObject:filedata forKey:@"keyfordata"];
[defaults synchronize];

in the app delegate of consuming app fetch the data from NSUserDefaults

another way is to use share extension- http://easynativeextensions.com/how-to-launch-your-app-from-the-ios-8-share-menu/

0

You can refer MGInstagram files as Instagram mobile app works same. You can pass image from your application to Instagram application.

You can download it from here: https://github.com/mglagola/MGInstagram

Hope this helps.

Dharmesh Siddhpura
  • 1,610
  • 12
  • 22