Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Social
- class ViewController: UIViewController {
- @IBAction func share(_ sender: Any) {
- // This is an notification giving you a option to share the app
- let alert = UIAlertController (title:"Share App" , message: "Share Case 20!", preferredStyle: .actionSheet )
- //First Action
- // This is an facebook option
- let firstaction = UIAlertAction (title: "Share on Facebook", style: .default) { (action) in
- // Checkingif user is connected to facebook
- if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook)
- {
- let post = SLComposeViewController(forServiceType: SLServiceTypeFacebook)!
- post.setInitialText("Case 20")
- post.add(UIImage(named: "Play"))
- self.present(post, animated: true, completion: nil)
- } else { self.showAlert(service: "Facebook")}
- }
- //Add Action to action sheet
- alert.addAction (firstaction)
- // present action
- self.present(alert, animated: true, completion: nil )
- func showAlert (service:String)
- {
- let alert = UIAlertController(title: "Error", message: "You are sadly not connected with to (service). Please connect before sharing! " , preferredStyle: .alert)
- let action = UIAlertAction (title: "Dismiss", style: .cancel, handler: nil )
- alert.addAction(action)
- present(alert, animated: true , completion: nil)
- }
- func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- }
- func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement