0

I have an iOS App that uses an UIActivityViewController to share files. It works perfectly on iPad, iPhone and on Mac using (Made for iPad). But when I test the Mac Catalyst app it works perfectly except "Save" and "Copy" are missing from the Share Panel. I think it must be an issue with entitlements and the sandbox. I have tried every folder location available from FileManager.default. If I send the file content as Data rather than a URL that only works on iPad/iPhone while Mac Catalyst share panel shows no options at all.

I tried using url.startAccessingSecurityScopedResource() but that always returned false and made no difference.

I have set the App Sandbox entitlements to Read/Write for User Selected File.

There must be a location where I can save the temporary file and the Share Panel can access it for file Save and Copy actions? Any ideas on the file path? Thanks

Share panel when Mac Catalyst or (Designed for iPad)

Entitlements

Here is the code.

// dataToShare is initialised with the actual data for the file to export, 
// before the UIActivityViewController is called
// data is presented to the UIActivityViewController using UIActivityItemSource
 var dataToShare = Data()
func proceedToShare(sender: UIViewController, anchorButton: UIView) {
// activityController is a retained var
 activityController = UIActivityViewController(activityItems: [self], applicationActivities: nil)
 activityController.completionWithItemsHandler = {_,_,_,_ in sender.navigationController?.popViewController(animated: true) }
 if UIDevice.current.userInterfaceIdiom == .pad {
 // also MacCatalyst and madeForIpad
 activityController.popoverPresentationController?.sourceView = anchorButton
 activityController.modalPresentationStyle = .popover
 } else {
 activityController.isModalInPresentation = true
 }
 sender.present(activityController, animated: true)
}
func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
 return fileContentForExport()
}
func fileContentForExport() -> Any {
 if ProcessInfo().isMacCatalystApp {
 /* This is called for both MacCatalyst and iOS (designed For iPad apps) */
 let directoryURL = FileManager.default.temporaryDirectory
 let filename = "ExportFile.txt"
 let fileURL = directoryURL.appendingPathComponent(filename))
 do {
 try dataToShare.write(to: fileURL)
 return fileURL
 } catch let error { print(error.localizedDescription) }
 }
 /* iPhone and iPad on iOS handle data directly */
 return dataToShare
}
asked Mar 24, 2025 at 14:28
0

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.