swift share extension不分享amzon项目

时间:2017-12-25 13:33:58

标签: ios swift ios8-share-extension share-extension

在我的应用中我整合了分享扩展。当我分享野生动物园页面时,我能够获得网址。但是当我去亚马逊网站或应用程序。当我点击任何产品的股票期权时,我的股票延期没有显示。 这是我的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>

这是我的.js

    var GetURL = function() {};
GetURL.prototype = {
    run: function(arguments) {
        arguments.completionFunction({"URL": document.URL});
    }
};
var ExtensionPreprocessingJS = new GetURL;

这就是我访问网址和图片的方式

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")
    }

}

0 个答案:

没有答案