iOS Share Extension with custom View Controller
Well, digging and searching a bit more I found out that I had to make my ShareViewController a subclass of UIViewController instead of ** SLComposeServiceViewController**. As I designed my interface on storyboard, I left the .plist as it was, but had to take into account the problem of VC going full screen described here: iOS 8 Share Extension custom view controller size
I took @Dale answer there for solving it.
These general steps worked for me without using SLComposeServiceViewController
(here's the code at the commit when it was implemented). The image at the end shows our result, but step 6 can be anything, not just a form.
Steps:
(code) Change
ShareViewController
to simpleUIViewController
(code) Add blur effect to
ShareViewController
(storyboard) Add container view to
ShareViewController
(storyboard) Add navigation controller
(storyboard) Embed navigation controller in
ShareViewController
's container viewCustomize the view controllers in the navigation controller (see this SO thread for example)
Step 1. Change ShareViewController
to simple UIViewController
import UIKit
class ShareViewController: UIViewController {
// ^^^^^^^^^^^^^^^^
Step 2. Add blur effect to ShareViewController
// ShareViewController continued from Step 1.
override func viewDidLoad() {
super.viewDidLoad()
// https://stackoverflow.com/questions/17041669/creating-a-blurring-overlay-view/25706250
// only apply the blur if the user hasn't disabled transparency effects
if UIAccessibilityIsReduceTransparencyEnabled() == false {
view.backgroundColor = .clear
let blurEffect = UIBlurEffect(style: .dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
//always fill the view
blurEffectView.frame = self.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.insertSubview(blurEffectView, at: 0)
} else {
view.backgroundColor = .black
}
// Do any additional setup after loading the view.
}
Step 3. Add container view to ShareViewController
Drag a Container View
from the Object Library into the ShareViewController
on the storyboard, and adjust dimension. For example:
Step 4. Add navigation controller
Drag a Navigation Controller from the Object Library to the storyboard.
Step 5. Embed navigation controller in ShareViewController
's container view
Control-drag from the container view of ShareViewController
to the navigation controller, select "Embed" from the menu. Should look similar to this:
Step 6. Customize the view controllers in the navigation controller (see this SO thread for example)
My result:
According to Apple, you can simply deactivate the default VC upon creation of the Extension. See the note under "Use the Xcode Share Template" section.
https://developer.apple.com/library/archive/documentation/General/Conceptual/ExtensibilityPG/Share.html