Reputation: 359
I am creating an iOS application that organizes books. The user is able export his/her "library" to a custom file type to backup or share with others. It would be good if other apps, e.g. GoodReader, would be able to open it so that the user can put it on a server or such. I understand that no app except mine can open the file, but others can still manage the file and move it around.
How do I do it?
Edited with more info
NSString *tempPath = NSTemporaryDirectory();
NSString *filePath = [tempPath stringByAppendingPathComponent:@"bksFileExport.bks"];
[self.activityItem writeToFile:filePath
atomically:NO];
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
self.documentInteractionController.UTI = @".bks";
[self.documentInteractionController presentOpenInMenuFromBarButtonItem:self.barButtonItemToOpenFrom
animated:YES];
This is the code I use to open the document interaction controller. I only included the relevant parts. When I use this exact same code for a .txt file it works. Now it does not.
I have not done anything to my Info.plist file, manybe I should?
Edited again with more things I have tried
This is what I have done now according the answer and the comments. (The icon is just a placeholder). It still doesn't work. No other app shows up when I want to export my custom file.
Upvotes: 3
Views: 1890
Reputation: 495
Steps taken from this guide.
Open your projects target and go to the info tab
Expand the Imported UTIs tab and add a new one and fill in
UITypeTagSpecification
with a type of Dictionary. Add a key of public.filename-extension
of type array into your dictionary and in the array create items with a string value of the file extension.
Expand the Exported UTIs tab and fill out the folloing
Once you've done this your app should be registered to open your file type. When a user opens a file to your app, -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
will be called to your AppDelegate. The files being opened by your app are stored in a filed called "inbox" inside your apps documents folder.
Upvotes: 2