Search code examples
iosswiftios-extensions

Full screen iOS share Extension


I know how to create an iOS share extension, but what I can't figure out is if there is a way to make it fullscreen such as an Action extension?

Pinterest seem to do this but I'm not sure how.

The docs for an Action extension say to use:

          <key>NSExtensionActionWantsFullScreenPresentation</key>
    <true/>

In the plist file for the extension but this doesn't seem to have an effect in the Share extension?

Is there anyway to accomplish this?


Solution

  • You can get ideas from there iOS Full Screen Share Extension and you can find the updated syntax for the code snippets below which is compatible with Swift 3 and Swift 4

    EntryViewController

    import UIKit
    
    @objc(EntryViewController)
    
    class EntryViewController : UINavigationController {
    
        override init(rootViewController: UIViewController) {
            super.init(rootViewController: ShareViewController())
        }
    
        required init(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)!
        }
    
        override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
            super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        }
    
        override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
            self.view.transform = CGAffineTransform(translationX: 0, y: self.view.frame.size.height)
            UIView.animate(withDuration: 0.3, animations: { () -> Void in
                self.view.transform = .identity
            })
        }
    
    }
    

    ShareViewController

    import UIKit
    import Social
    
    class ShareViewController: SLComposeServiceViewController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            self.view.backgroundColor = UIColor.white
            self.navigationItem.title = "Share"
    
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: Selector(("cancelButtonTapped:")))
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: Selector(("saveButtonTapped:")))
        }
    
        func saveButtonTapped(sender: UIBarButtonItem) {
            self.hideExtensionWithCompletionHandler(completion: { (Bool) -> Void in
            self.extensionContext!.completeRequest(returningItems: nil, completionHandler: nil)
            })
        }
    
        func cancelButtonTapped(sender: UIBarButtonItem) {
            self.hideExtensionWithCompletionHandler(completion: { (Bool) -> Void in
            self.extensionContext!.cancelRequest(withError: NSError())
            })
        }
    
        func hideExtensionWithCompletionHandler(completion: @escaping (Bool) -> Void) {
            UIView.animate(withDuration: 0.3, animations: { 
            self.navigationController!.view.transform = CGAffineTransform(translationX: 0, y: self.navigationController!.view.frame.size.height)
            }, completion: completion)
        }
    
    }