I'm creating a Share Extension to allow to share Youtube videos into my app and am having a hard time to present my custom UI smoothly. Instead of the default view controller which just contains the raw Youtube URL, I want to do something visually similar to Facebook's extension, displaying a thumbnail and the video title. My first attempt at it was editing the MainInterface storyboard ShareViewController, but doing so briefly shows my custom interface and thet get's "overriden" by the default UI layout. So I ended up adding another view controller with my UI to the storyboard and in the ShareViewController I added
override func presentationAnimationDidFinish() {
super.presentationAnimationDidFinish()
DispatchQueue.main.async {
self.pushConfigurationViewController(customVC)
}
The problem with this obviously is that I still get to see the default View Controller before my custom one is pushed. So the question would be how do I get to show my custom UI right away when the share extension is started? I've experimented with the NSExtensionPrincipalClass in the .plist but did not have any positive results
Thanks in advance
To add a share extension to your app, open your app's project in Xcode and select File > New > Target from the menu bar. Xcode presents a sheet that contains templates for different kinds of targets. Select the share extension template from the iOS pane and follow the steps in Xcode's interface to add one to your app.
The Share Sheet is the collection of actions that become available when you tap the Share icon available in most of the common app. For example, if you wanted to send someone a photo from the Photo Library, you would display the photo in the Photos app and tap Share in order to see the send options.
App Extensions are an iOS feature that allows developers to extend the functionality and content of their app beyond the app itself, making it available to users in other apps or in the main operating system.
The main feature of share extensions is to make your content preview correctly on Workplace. This entails providing support for authenticated preview metadata in a format Workplace expects, such that when URLs to your content are shared, Workplace can fetch that metadata and create a preview.
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 simple UIViewController
(code) Add blur effect to ShareViewController
(storyboard) Add container view to ShareViewController
(storyboard) Add navigation controller
(storyboard) Embed navigation controller in ShareViewController
's container view
Customize the view controllers in the navigation controller (see this SO thread for example)
ShareViewController
to simple UIViewController
import UIKit
class ShareViewController: UIViewController {
// ^^^^^^^^^^^^^^^^
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.
}
ShareViewController
Drag a Container View
from the Object Library into the ShareViewController
on the storyboard, and adjust dimension. For example:
Drag a Navigation Controller from the Object Library to the storyboard.
ShareViewController
's container viewControl-drag from the container view of ShareViewController
to the navigation controller, select "Embed" from the menu. Should look similar to this:
My result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With