Background I have an Action Extension which can be used with images:
class ActionViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
var imageFound = false
for item in self.extensionContext!.inputItems as! [NSExtensionItem] {
for provider in item.attachments! {
if provider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
weak var weakImageView = self.imageView
provider.loadItem(forTypeIdentifier: kUTTypeImage as String, options: nil, completionHandler: { (imageURL, error) in
OperationQueue.main.addOperation {
if let strongImageView = weakImageView {
if let imageURL = imageURL as? URL {
strongImageView.image = UIImage(data: try! Data(contentsOf: imageURL))
}
}
}
})
imageFound = true
break
}
}
if (imageFound) {
break
}
}
}
The above code is the default code when you create an Action Extension. The above code executes properly if I am in the Photos
app > Select an image > Share > My Action Extension. The image is then displayed in a UIImageView in my Action Extension. However when I take a screenshot and press the share button (see below image for example), sharing the image with my Action Extension returns a blank screen with no errors in the console. This similarly happens with other apps. I noticed that it is possible to share from the Instant Markup tool, since I am able to share an image with Gmail.
The following is my Info.plist:
<key>NSExtensionActivationRule</key>
<string>SUBQUERY (
extensionItems,
$extensionItem,
SUBQUERY (
$extensionItem.attachments,
$attachment,
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.item" ||
ANY $attachment.registeredTypeIdentifiers UTI-CONFORMS-TO "public.content"
).@count == $extensionItem.attachments.@count
).@count > 0
</string>
The problem: I am not entirely sure how to fetch the image from Instant Markup tool (built in iOS screenshot tool).