简体   繁体   中英

Objective-C - inter-app communication

I have an app that list a list of files in a UITableView. These files are .ifc files (3D renderings) I have this other app that I downloaded called Field3D which displays downloaded .ifc files. Currently my app does download this file and I am looking for away to use UIActivityViewController so the user can share this file with the Field3D app. I was told that inter-app communication was the way to go, so I did some research and found this https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html

Now it says under Sending Files and Data to Another App that all I have to do is the following:

- (void)displayActivityControllerWithDataObject:(id)obj {
   UIActivityViewController* vc = [[UIActivityViewController alloc]
                                initWithActivityItems:@[obj] applicationActivities:nil];
    [self presentViewController:vc animated:YES completion:nil];
}

but I don't believe this will work just like that because my code for the UIActivityViewController is very simliar

NSData *pdfData = [NSData dataWithContentsOfFile:filePath];

            UIActivityViewController * activityController = [[UIActivityViewController alloc] initWithActivityItems:@[pdfData] applicationActivities:nil];

            activityController.popoverPresentationController.sourceView = self.view;

            [self presentViewController:activityController animated:YES completion:^{}];

Can someone help me out and point me in the right direction?

You should be able to use UIDocumentInteractionController to let the user open the file with Field3D.

An iOS app is distributed as an “IPA” file, which is just a ZIP file containing the app bundle and some other metadata files. I downloaded Field3D in iTunes and unzipped the IPA, then took a look at the app's Info.plist (using plutil -convert json -r -o - Info.plist ) to see what document types it is registered for. Amongst others, it registers itself as a handler for com.tekla.collada3d.ifc with filename extension ifc and com.tekla.collada3d.ifczip with filename extension ifczip .

So if you have the file stored locally (presumably in your app sandbox's Documents or Caches directory) with an extension of .ifc or .ifczip , you should be able to let Field3D handle it just by presenting a UIDocumentInteractionController initialized with the URL of the (local) file. If you want, you can explicitly set the interaction controller's UTI property to com.tekla.collada3d.ifc or com.tekla.collada3d.ifczip instead of relying on the filename extension.

For more information, read “Previewing and Opening Files” in Document Interaction Programming Topics for iOS .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM