问题
in my app i integrated share extension. and i am able to get url when i am sharing safari page. but when i go on amazon site or app. and when i am tapping on share option of any product my share extension is not showing. Here is my info.plist
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<string>TRUEPREDICATE</string>
<key>NSExtensionJavaScriptPreprocessingFile</key>
<string>GetURL</string>
</dict>
<key>NSExtensionMainStoryboard</key>
<string>MainInterface</string>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.share-services</string>
</dict>
here its my .js
var GetURL = function() {};
GetURL.prototype = {
run: function(arguments) {
arguments.completionFunction({"URL": document.URL});
}
};
var ExtensionPreprocessingJS = new GetURL;
this is how i am accessing url and image
private func getURL() {
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,
let urlString = results["URL"] as? String,
let url = NSURL(string: urlString) {
self.url = url
}
}
})
} else {
print("error")
}
let propertyListImage = String(kUTTypeImage)
if itemProvider.hasItemConformingToTypeIdentifier(propertyListImage) {
itemProvider.loadItem(forTypeIdentifier: propertyListImage, options: nil, completionHandler: { (item, error) -> Void in
self.imgURL = item as! NSURL
guard let dictionary = item as? NSDictionary else { return }
OperationQueue.main.addOperation {
if let results = dictionary[NSExtensionJavaScriptPreprocessingResultsKey] as? NSDictionary,
let urlString = results["URL"] as? String,
let url = NSURL(string: urlString) {
self.imgURL = url
}
}
})
} else {
print("error")
}
}
来源:https://stackoverflow.com/questions/47969115/swift-share-extension-not-sharing-amzon-item