I am trying to share my custom type ".stccourse" via UIActivityViewController. I can Airdrop the file to my mac from my iPad but when I try to mail it, I don't get any file attachment. I do see the text as message body but no attachment. Following is my code:
@IBAction func didTapShareButton(sender: UIBarButtonItem) {
do {
// Get course zip
if let courseZipDict = try STCCourseManager.sharedInstance.getZippedCurrentCourse(), let courseZipData = courseZipDict["courseZip"] as? NSData {
let fileManager = NSFileManager()
// Write courseZip to Temp folder
let filePath = NSTemporaryDirectory().stringByAppendingPathComponent("\(STCCourseManager.sharedInstance.currentCourse?.title).stccourse")
try self.writeData(courseZipData, toFilePath: filePath)
// Create activity view controller
let shareVC = UIActivityViewController(activityItems: ["Course shared", NSURL(fileURLWithPath: filePath)], applicationActivities: nil)
shareVC.popoverPresentationController?.sourceView = self.view
shareVC.popoverPresentationController?.barButtonItem = self.shareButton
self.presentViewController(shareVC, animated: true, completion: nil)
}
} catch {
print("Failed with error: \(error)")
}
}
I am not sure what am I missing here. Any help would be appreciated. Thanks
I have also added my custom type UTI to Info.plist:
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
<string>public.archive</string>
<string>com.pkware.zip-archive</string>
</array>
<key>UTTypeDescription</key>
<string>STCCourse File</string>
<key>UTTypeIdentifier</key>
<string>com.vik.stccourse</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>stccourse</string>
</array>
</dict>
</dict>
</array>
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
<string>public.archive</string>
<string>com.pkware.zip-archive</string>
</array>
<key>UTTypeDescription</key>
<string>STCCourse File</string>
<key>UTTypeIdentifier</key>
<string>com.vik.stccourse</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>stccourse</string>
</array>
<key>public.mime-type</key>
<string>application/myappname</string>
</dict>
</dict>
</array>