I can't seem to understand how to get a custom share view controller fired up. My understanding is that the SLComposeServiceViewController class provides the developer with a barebones compose view, much like the already-provided service types Facebook and Twitter, and the developer has to implement his or her own features. If that's the case, shouldn't I just init the SLComposeServiceViewController like any other VC and present it?
From my understanding, it seems that the class is meant to be subclassed for functionality.
You could make a very simple subclass if you want to make it dynamic
enum ComposeServiceResult {
case Cancel
case Post
}
class ComposeServiceViewController: SLComposeServiceViewController {
var completionHandler : ((result:ComposeServiceResult, text:String) -> Void)!
override func didSelectCancel() {
completionHandler(result: .Cancel, text: self.contentText)
self.navigationController?.dismissViewControllerAnimated(true, completion: nil)
}
override func didSelectPost() {
completionHandler(result: .Post, text: "")
self.navigationController?.dismissViewControllerAnimated(true, completion: nil)
}
}
and then present it
var composeVC = ComposeServiceViewController()
composeVC.title = "Facebook"
composeVC.placeholder = "Add a caption!"
composeVC.completionHandler = completionHandler
composeVC.modalPresentationStyle = .OverCurrentContext;
presentViewController(composeVC, animated: true, completion: nil)
I also think you can dig into SLComposeSheetConfigurationItem for better customization but I have not done that myself.
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