Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSExtension warnings when UIActivityViewController selects AirDrop

Tags:

swift

I'm getting the next warning on the Xcode console:

[NSExtension] Extension request contains input items but the extension point does not specify a set of allowed payload classes. The extension point's NSExtensionContext subclass must implement `+_allowedItemPayloadClasses`. This must return the set of allowed NSExtensionItem payload classes. In future, this request will fail with an error. Extension: <EXConcreteExtension: 0x283a54cc0> {id = com.apple.Sharing.AirDrop} Items: (
"<NSExtensionItem: 0x280d73a40> - userInfo: {\n    ShowNoContentView = 1;\n}"

)

The code I have implemented it's basically a UIActivityViewController which receives a CSV document.

let activityController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
    
    activityController.completionWithItemsHandler = {
        (_, _, _, _) in
    }
    
    activityController.excludedActivityTypes = [
        UIActivity.ActivityType.assignToContact,
        ...,
        ...
    ]

    activityController.popoverPresentationController?.sourceRect = self.view.frame
    activityController.popoverPresentationController?.barButtonItem = navigationItem.rightBarButtonItem

    self.present(activityController, animated: true)

The code it's working correctly but I would like to fix that warning. I only have a notification extension, I don't know why it's appearing this warning.

like image 869
tzonGoza Avatar asked Sep 12 '25 14:09

tzonGoza


1 Answers

Create a subclass of NSExtensionContext that conforms to the _allowedItemPayloadClasses protocol and returns the set of allowed payload classes for your extension.

Here is an example implementation:

class MyExtensionContext: NSExtensionContext {
    override class func _allowedItemPayloadClasses() -> Set<AnyHashable> {
        return [NSURL.self, UIImage.self, NSString.self]
    }
}

let item = NSExtensionItem()
item.attachments = [/* attachments */]
item.setContext(MyExtensionContext())

This should resolve the warning and ensure that your extension works correctly with AirDrop.

like image 84
Irtaza fayaz Avatar answered Sep 15 '25 10:09

Irtaza fayaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!