How do you initialize and present a custom SLComposeServiceViewController?

I donโ€™t seem to understand how to start a custom controller for representing shared resources. I understand that the SLComposeServiceViewController class provides the developer with an idea of โ€‹โ€‹barebone compose, as well as the types of services Facebook and Twitter have already provided, and the developer must implement his own functions. If so, shouldn't I just run SLComposeServiceViewController, like any other VC, and submit it?

+5
source share
1 answer

In my opinion, it seems that the class is intended to be a subclass of functionality.

You can 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 introduce him

 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 that you can delve into the SLComposeSheetConfigurationItem for better customization, but I did not do it myself.

+3
source

Source: https://habr.com/ru/post/1204144/