How to remove "Add to iCloud Drive" from UIActivity controller?

I want to remove the "iCloud drive" option from the UIActivity Controller section. Here's a small snapshot.

enter image description here

I tried this but it doesn't work in swift 3.

activityViewController.excludedActivityTypes = [.assignToContact,.copyToPasteboard,.print,.saveToCameraRoll,.addToReadingList,UIActivityType(rawValue: "com.apple.reminders.RemindersEditorExtension"),UIActivityType(rawValue: "com.apple.mobilenotes.SharingExtension"),UIActivityType(rawValue: "com.apple.iCloudDrive.ShareExtension"),UIActivityType(rawValue: "com.apple.mobileslideshow.StreamShareService")]

      

+3


source to share


1 answer


May help depending on version :

Apple continues to change the bundle ID for this extension. You may need to exclude this as well, but depends on the iOS SDK version:

UIActivityType(rawValue: "com.apple.CloudDocsUI.AddToiCloudDrive")

      

Position providers for user after user selection:

You can also pass UIActivityItemProvider objects instead of raw objects to your UIActivityViewController initializer. This unfortunately does not change which options are enabled in the UI, but will stop working if there is no item after the user selects.

First, create a new class for your provider. You can use this to return different content based on different providers! That is, image and text for mail, text only for iMessage.

class ShareActivityItemProvider: UIActivityItemProvider {
override func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivityType) -> Any? {
    print("activity type selected: \(activityType.rawValue)")
    // These are your accepted activity types
    if activityType == .postToFacebook || activityType == .postToTwitter || activityType == .postToWeibo || activityType == .mail || activityType == .message {
        return placeholderItem
    }
    return nil
}

      

}



Then you initialize your UIActivityItemProvider like this:

let avc = UIActivityViewController(activityItems: [ShareActivityItemProvider(placeholderItem: "Test message or any object")], applicationActivities: nil)

      

Or a hacky but legal way to do what you want:

After above, you can add a blank UIImage space, remove the additional options that are now available, and only return what you want from your provider:

let avc = UIActivityViewController(activityItems: [ShareActivityItemProvider(placeholderItem: "Test message or any object"), ShareActivityItemProvider(placeholderItem: UIImage())], applicationActivities: nil)

      

avc.excludedActivityTypes = [.assignToContact, .saveToCameraRoll, ... others ...]

class ShareActivityItemProvider: UIActivityItemProvider {
override func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivityType) -> Any? {
    print("activity type \(activityType.rawValue) \(activityType)")
    if placeholderItem is String, activityType == .postToFacebook || activityType == .postToTwitter || activityType == .postToWeibo || activityType == .mail || activityType == .message {
        return placeholderItem
    }
    return nil
}

      

}



+2


source







All Articles