swift share extension not sharing amzon item

耗尽温柔 提交于 2020-01-05 08:37:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!