I need to show my App in UIActivityViewController for All Applications as Action Extension(Default)

Sanju picture Sanju · Feb 8, 2016 · Viewed 7.4k times · Source

Created New Project and Added ActionExtension it worked and shows in Action Activities But Action Extension doesn't show in Device when i created for Existing App(Old App which contains swift and Objective-c Files) I need to show my App in Action Extension of UiactivityController but i am unable to show For Every Application in Device refer image

image1 image2

***Query : While in Simulator(Photos App) it shows and it Doesn't shows in Other Apps in Simulator but when i run in Device it Doesn't shows in both Photos App and others

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

Referred Apple Documentation and other links

http://code.tutsplus.com/tutorials/ios-8-how-to-build-a-simple-action-extension--cms-22794

on Extensions didn't find any relevant answer and my Action Extension Plist File (refer image)

enter image description here

**I am unable to show my app in UiactivityViewController Please Help

Answer

Sanju picture Sanju · Feb 19, 2016

Now, I am able to show my AppExtension in UIActivityViewController

I took my Old Project again and added Target -> Action Extension Newly

How to add Target?

Xcode -> File -> create New Target -> select Action Extension -> Done

Things to do in .plist:

In Plist Added like shown in 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>

Result:

enter image description here

Refer links

http://code.tutsplus.com/tutorials/ios-8-how-to-build-a-simple-action-extension--cms-22794

http://www.appcoda.com/tag/app-extension/