Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. import UIKit
  2. import Social
  3.  
  4. class ViewController: UIViewController {
  5.  
  6. @IBAction func share(_ sender: Any) {
  7.  
  8. // This is an notification giving you a option to share the app
  9. let alert = UIAlertController (title:"Share App" , message: "Share Case 20!", preferredStyle: .actionSheet )
  10.  
  11. //First Action
  12. // This is an facebook option
  13. let firstaction = UIAlertAction (title: "Share on Facebook", style: .default) { (action) in
  14.  
  15. // Checkingif user is connected to facebook
  16. if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook)
  17. {
  18. let post = SLComposeViewController(forServiceType: SLServiceTypeFacebook)!
  19.  
  20. post.setInitialText("Case 20")
  21. post.add(UIImage(named: "Play"))
  22.  
  23. self.present(post, animated: true, completion: nil)
  24.  
  25. } else { self.showAlert(service: "Facebook")}
  26. }
  27. //Add Action to action sheet
  28. alert.addAction (firstaction)
  29.  
  30. // present action
  31.  
  32. self.present(alert, animated: true, completion: nil )
  33.  
  34.  
  35. func showAlert (service:String)
  36. {
  37. let alert = UIAlertController(title: "Error", message: "You are sadly not connected with to (service). Please connect before sharing! " , preferredStyle: .alert)
  38.  
  39. let action = UIAlertAction (title: "Dismiss", style: .cancel, handler: nil )
  40.  
  41. alert.addAction(action)
  42. present(alert, animated: true , completion: nil)
  43. }
  44.  
  45. func viewDidLoad() {
  46. super.viewDidLoad()
  47. // Do any additional setup after loading the view, typically from a nib.
  48. }
  49.  
  50. func didReceiveMemoryWarning() {
  51. super.didReceiveMemoryWarning()
  52. // Dispose of any resources that can be recreated.
  53. }
  54.  
  55.  
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement