In my app, I need to send some custom data files from one device to another, and I am trying to do this with Mail, iMessage/Message and Airdrop.
This works fine with Mail and Airdrop but with iMessage and it goes just fine, but on the receiving end, I am not able to open the files. It's just not allowing me to do anything with it.
Any ideas??
This is what my Document Type looks like:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFile</key>
<string>abc.png</string>
<key>CFBundleTypeName</key>
<string>ABC Custom Data type</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>Handler Rank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>com.company.abc.wd</string>
</array>
</dict>
</array>
This is how i am sending the data:
NSMutableDictionary * dict = [NSMutableDictionary dictionary];
[dict setObject:currentDataSet forKey:@"actualData"];
NSData * meetingData = [NSKeyedArchiver archivedDataWithRootObject:dict];
Meeting * dataItem = [[Meeting alloc]initWithData:meetingData
type:@"com.abc.xyz.wd" subject:@"Meeting"
previewImage:[UIImage imageNamed:@"appIcon.png"]];
UIActivityViewController * activityController =
[[UIActivityViewController alloc]initWithActivityItems:@[dataItem]
applicationActivities:nil];
activityController.excludedActivityTypes =
@[UIActivityTypePostToTwitter, UIActivityTypePostToWeibo];
[self presentViewController:activityController animated:YES completion:nil];
An . ipa file is an iOS and iPadOS application archive file which stores an iOS/iPadOS app.
Send a fileTouch and hold the file, then tap Share. Tip: To send a smaller version of the file, tap Compress before you tap Share. Then touch and hold the compressed version of the file (identified as a zip file), and tap Share. Choose an option for sending (for example, AirDrop, Messages, or Mail), then tap Send.
This answer is correct in that the custom document can be opened from Messages if it conforms to public.text
. The drawback to this solution is that the document is previewed as raw text, which might not be the desired result.
Documents conforming to public.data
can be opened from the Messages app without being previewed as raw text by creating a Quick Look Preview Extension. There isn't much documentation about how to build a Quick Look Preview Extension, but it's pretty straightforward:
In Xcode, choose, File
> New
> Target
.
Choose Quick Look Preview Extension, give your extension a name, and click Finish.
In the info.plist
for the newly created extension, add a new item under NSExtension
> NSExtensionAttributes
> QLSupportedContentTypes
, and set the value for this item to your app's custom document type. For example:
...
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>QLSupportedContentTypes</key>
<array>
<string>com.company.abc.wd</string>
</array>
<key>QLSupportsSearchableItems</key>
<true/>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.quicklook.preview</string>
</dict>
...
Use MainInterface.storyboard
and PreviewViewController
to define the layout of your custom Quick Look preview. More specifically, read data from the URL provided in the preparePreviewOfFile
function and populate the ViewController accordingly. A brief example (in Swift 4):
func preparePreviewOfFile(at url: URL, completionHandler handler: @escaping (Error?) -> Void) {
do {
let documentData = try Data(contentsOf: url)
// Populate the ViewController with a preview of the document.
handler(nil)
} catch let error {
handler(error)
}
}
Some pitfalls I ran into when creating my extension:
The exported UTI identifier had to be all lower case. When some of the characters were upper case, the Quick Look preview was never shown, even though I used the same capitalization in my Quick Look Preview Extension.
Quick Look Preview Extensions are not allowed to link against dynamic libraries. If a dynamic library is linked, the Quick Look preview will not load.
The Quick Look ViewController is not allowed to have any buttons. If it contains a button, the Quick Look preview will not load.
Additional resources:
Building Great Document-based Apps in iOS 11 (WWDC 2017 Video)
Quick Look Previews from the Ground Up (WWDC 2018 Video)
QuickLook Documentation
I came across this post while searching for a similar solution. I was able to email custom files from my app and open it in email or use it with AirDrop. If I sent it via iMessage it even showed up with my custom icon, but when I tapped it in iMessage nothing happened.
Be aware that you need something like the following in your plist file (from How do I associate file types with an iPhone application?)
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.plain-text</string>
<string>public.text</string>
</array>
<key>UTTypeDescription</key>
<string>Molecules Structure File</string>
<key>UTTypeIdentifier</key>
<string>com.sunsetlakesoftware.molecules.pdb</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<string>pdb</string>
<key>public.mime-type</key>
<string>chemical/x-pdb</string>
</dict>
</dict>
NOTE: I had something very similar for my app BUT in the UTTypeConformsTo I only had public.data since my files are zipped data files.
I found that by adding public.text as a second item in the array it would be actionable in iMessage. On a further note, if I added public.plain-text as a third item my file ended up with a Pages icon instead of my icon (so I removed it)
I hope this helps someone. It's taken me hours to get to the bottom of it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With