swift2 我需要在所有应用程序的UIActivityViewController中将我的应用程序显示为操作扩展(默认)

yqlxgs2m  于 2022-11-06  发布在  Swift
关注(0)|答案(1)|浏览(177)

创建了新项目并添加了ActionExtension,它工作并显示在Action Activities中,但当我为现有应用程序(包含swift和Objective-c文件的旧应用程序)创建时,Action Extension未显示在设备中。我需要在UiactivityController的Action Extension中显示我的应用程序,但我无法显示For Every Application in Device(设备中的每个应用程序)参考图像
x1c 0d1x

***质询:在模拟器(照片应用程序)中显示,但在模拟器的其他应用程序中未显示,但在设备中运行时,照片应用程序和其他应用程序中均未显示

override func viewDidLoad() {
    super.viewDidLoad()

    // Get the item[s] we're handling from the extension context.

    // For example, look for an image and place it into an image view.
    // Replace this with something appropriate for the type[s] your extension supports.
    var imageFound = false
    for item: AnyObject in self.extensionContext!.inputItems {
        let inputItem = item as! NSExtensionItem
        for provider: AnyObject in inputItem.attachments! {
            let itemProvider = provider as! NSItemProvider
            if itemProvider.hasItemConformingToTypeIdentifier(kUTTypeImage as String) {
                // This is an image. We'll load it, then place it in our image view.
                weak var weakImageView = self.imageView
                itemProvider.loadItemForTypeIdentifier(kUTTypeImage as String, options: nil, completionHandler: { (image, error) in
                    NSOperationQueue.mainQueue().addOperationWithBlock {

                        if let strongImageView = weakImageView {

                            if let imageURL = image as? NSURL{
                                strongImageView.image = UIImage(data: NSData(contentsOfURL: imageURL)!)
                            }else{

                strongImageView.image = image as? UIImage
                            }
                        }

                    }
                })

                imageFound = true
                break
            }
        }

        if (imageFound) {
            // We only handle one image, so stop looking for more.
            break
        }
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func done() {
    // Return any edited content to the host app.
    // This template doesn't do anything, so we just echo the passed in items.
    self.extensionContext!.completeRequestReturningItems(self.extensionContext!.inputItems, completionHandler: nil)
}

引用的Apple文稿和其他链接
http://code.tutsplus.com/tutorials/ios-8-how-to-build-a-simple-action-extension--cms-22794
在扩展上未找到任何相关答案和我的操作扩展Plist文件(请参考图片)

**我无法在UiactivityViewController中显示我的应用程序请帮助

j9per5c4

j9per5c41#

现在,我可以在UIActivityViewController中显示AppExtension了
我把我的老项目再次添加目标-〉行动扩展新

如何添加目标?

Xcode -〉文件-〉创建新目标-〉选择操作扩展-〉完成

在.plist中要做的事情:

在Plist中添加,如Png中所示
http://i.stack.imgur.com/KBwdil.png

<key>NSExtension</key>
<dict>
    <key>NSExtensionAttributes</key>
    <dict>
        <key>NSExtensionActivationRule</key>
        <dict>
            <key>NSExtensionActivationSupportsImageWithMaxCount</key>
            <integer>1</integer>
        </dict>
    </dict>
    <key>NSExtensionMainStoryboard</key>
    <string>MainInterface</string>
    <key>NSExtensionPointIdentifier</key>
    <string>com.apple.ui-services</string>
</dict>

结果:

引用链接
http://code.tutsplus.com/tutorials/ios-8-how-to-build-a-simple-action-extension--cms-22794
http://www.appcoda.com/tag/app-extension/

相关问题