6.9 C
New York
Wednesday, March 26, 2025

ios – Mac Catalyst app doesn’t enable Save & Copy utilizing UIActivityViewController given a URL whereas (Made for iPad) does enable it


I’ve an iOS App that makes use of an UIActivityViewController to share recordsdata. It really works completely on iPad, iPhone and on Mac utilizing (Made for iPad). However once I check the Mac Catalyst app it really works completely besides “Save” and “Copy” are lacking from the Share Panel.
I feel it have to be a problem with entitlements and the sandbox. I’ve tried each folder location obtainable from FileManager.default.
If I ship the file content material as Information fairly than a URL that solely works on iPad/iPhone whereas Mac Catalyst share panel reveals no choices in any respect.

I attempted utilizing url.startAccessingSecurityScopedResource() however that at all times returned false and made no distinction.

I’ve set the App Sandbox entitlements to Learn/Write for Person Chosen File.

There have to be a location the place I can save the momentary file and the Share Panel can entry it? Any concepts on the file path?
Thanks

Share panel when Mac Catalyst or (Designed for iPad)

Entitlements

Right here is the code.

// dataToShare is initialised with the precise information for the file to export, 
// earlier than the UIActivityViewController known as
// information is introduced to the UIActivityViewController utilizing UIActivityItemSource
    var dataToShare = Information()

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.present.userInterfaceIdiom == .pad {
        // additionally MacCatalyst and madeForIpad
        activityController.popoverPresentationController?.sourceView = anchorButton
        activityController.modalPresentationStyle = .popover
    } else {
        activityController.isModalInPresentation = true
    }
    sender.current(activityController, animated: true)
}


func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
    return fileContentForExport()
}

func fileContentForExport() -> Any {
    if  ProcessInfo().isMacCatalystApp {
    /* That is known as for each MacCatalyst and iOS (designed For iPad apps) */
        let directoryURL = FileManager.default.temporaryDirectory
        let filename = "ExportFile.txt"
        let fileURL = directoryURL.appendingPathComponent(filename))
        do {
            strive dataToShare.write(to: fileURL)
            return fileURL
        } catch let error { print(error.localizedDescription) }
    }
    /* iPhone and iPad on iOS deal with information immediately */
    return dataToShare
}

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles