0

I need to exclude .saveToCameraRoll from a UIActivityViewController but it is ignoring excludedActivityTypes.

activityVC = UIActivityViewController(activityItems: [imgUrl], applicationActivities: activities)
activityVC!.excludedActivityTypes = [.saveToCameraRoll]

I also tried creating a "custom" UIActivty and exclude it:

let saveToCameraRollActivity = UIActivity.ActivityType.init(rawValue: "\(UIActivity.ActivityType.saveToCameraRoll.rawValue)")
activityVC!.excludedActivityTypes = [saveToCameraRollActivity]

Both ways have no effect, the Save Image option is still displayed. What is the point of being able to exclude activity types if they are ignored?

The header says:

// default is nil. activity types listed will not be displayed
excludedActivityTypes: [UIActivity.ActivityType]? 

I need to use my own Save Image because standard one is not respecting the file name (even though it is shown with the file icon and I am using a URL).

Jeshua Lacock
  • 5,730
  • 1
  • 28
  • 58
  • In one of my apps I can export an image using a `UIActivityViewController`. I just added a line to exclude the `.saveToCameraRoll` activity and when I do, the "Save Image" no longer appears. I tested passing a `UIImage` and passing an `NSURL`. Both worked as desired. I am using `UIActivityItemsConfiguration` to setup the activity view. Not sure if that makes a difference or not since `excludedActivityTypes` is set directly on the activity view and not the configuration. – HangarRash Nov 25 '22 at 06:09
  • Hmm not familiar with UIActivityItemsConfiguration. I can look it up or do you have a snippet? – Jeshua Lacock Nov 25 '22 at 06:10
  • It so happens I posted a question 2 days ago about custom `UIActivity` functionality and it has some of my `UIActivityItemsConfiguration` code in it. See https://stackoverflow.com/questions/74542203/how-to-get-the-title-and-messagebody-metadata-from-the-uiactivityviewcontroller – HangarRash Nov 25 '22 at 06:12
  • Thanks. Does that work with all the other standard stuff like AirDrop? It would be perfect as is, if it just used the existing filename. – Jeshua Lacock Nov 25 '22 at 06:15
  • I'm don't know what you mean. If you are asking if the shared URL gets saved via Airdrop with the same filename from the URL then yes, it does. – HangarRash Nov 25 '22 at 06:19

1 Answers1

-1

I am using this function and hide "save video" button :--

func otherShare(url : URL) {
      
        let imageToShare = [ url ]
        let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash

        activityViewController.excludedActivityTypes = [UIActivity.ActivityType.copyToPasteboard, UIActivity.ActivityType.saveToCameraRoll]

        self.present(activityViewController, animated: true, completion: nil)
}