Я хочу иметь возможность поделиться выделенным текстом, но мое расширение появляется только при нажатии на значок общего доступа (а затем оно заполняет поле заголовком страницы). Я хочу, чтобы мое расширение отображалось, когда пользователь выбирает текст и нажимает «Поделиться ...» (как на рисунке ниже), а затем я хочу, чтобы оно заполнило текстовую область выделенным текстом.
![I want extension to be accessible here](https://i.stack.imgur.com/leayNl.jpg)
Share View Controller:
override func viewDidLoad() {
super.viewDidLoad()
customPopup()
let extensionItem = extensionContext?.inputItems.first as! NSExtensionItem
let itemProvider = extensionItem.attachments?.first as! NSItemProvider
let propertyList = String(kUTTypePropertyList)
if itemProvider.hasItemConformingToTypeIdentifier(propertyList) {
itemProvider.loadItem(forTypeIdentifier: propertyList, options: nil, completionHandler: { (item, error) -> Void in
guard let dictionary = item as? NSDictionary else { return }
OperationQueue.main.addOperation {
if let results = dictionary[NSExtensionJavaScriptPreprocessingResultsKey] as? NSDictionary {
print("RESULTS: \n", results)
}
}
})
} else {
print("error")
}
}
Action.js (предварительная обработка JS)
var MyPreprocessor = function() {};
MyPreprocessor.prototype = {
run: function(arguments) {
arguments.completionFunction({"URL": document.URL, "title": document.title, "selection": window.getSelection().toString()});
}
};
var ExtensionPreprocessingJS = new MyPreprocessor;
Info.plist
![](https://i.stack.imgur.com/8A0C4.png)