SHARE
TWEET

Compartilhar

a guest Feb 19th, 2016 31 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import UIKit
  2. import FBSDKLoginKit
  3. import FBSDKShareKit
  4. import FBSDKMessengerShareKit
  5.  
  6. import Social
  7. class ViewController: UIViewController, UITextFieldDelegate {
  8.    
  9.     private let URL = NSURL(string: "http://graph.facebook.com/me")!
  10.    
  11.     let loginbutton = FBSDKLoginButton()
  12.    
  13.     override func viewDidLoad() {
  14.         super.viewDidLoad()
  15.        
  16.         loginbutton.center = self.view.center
  17.        
  18.         self.view.addSubview(loginbutton)
  19.     }
  20.    
  21.     @IBAction func abrirPagina(sender: AnyObject) {
  22.    
  23.         let url: NSURL = NSURL(string: "http://www.facebook.com/iswiftbr")!
  24.        
  25.         UIApplication.sharedApplication().openURL(url)
  26.  
  27.  
  28.     }
  29.    
  30.     @IBAction func shareDialog(sender: AnyObject) {
  31.    
  32.         let content = FBSDKShareLinkContent()
  33.         content.contentURL = NSURL(string: "http://www.facebook.com/iswiftbr")
  34.        
  35.         FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)
  36.         FBSDKMessageDialog.showWithContent(content, delegate: nil)
  37.        
  38.         let dialogo = FBSDKShareDialog()
  39.         dialogo.fromViewController = self
  40.        
  41.         dialogo.mode = FBSDKShareDialogMode.ShareSheet
  42.        
  43.         dialogo.show()
  44.        
  45.         FBSDKShareAPI.shareWithContent(content, delegate: nil)
  46.     }
  47.    
  48.     @IBAction func share(sender: AnyObject) {
  49.        
  50.         let shareMenu = UIAlertController(title: "Compartilhar", message: "", preferredStyle: .ActionSheet)
  51.        
  52.         let facebookAction = UIAlertAction(title: "Facebook", style: .Default) { (action) -> Void in
  53.            
  54.             guard SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) else {
  55.                
  56.                 let alertMessage = UIAlertController(title: "Facebook indisponível", message: "Você não registrou sua conta do Facebook. Por favor vá para Ajustes e crie uma conta.", preferredStyle: .Alert)
  57.                
  58.                 alertMessage.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
  59.                
  60.                 self.presentViewController(alertMessage, animated: true, completion: nil)
  61.                
  62.                 return
  63.             }
  64.             let facebookComposer = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
  65.             facebookComposer.setInitialText("Texto Inicial")
  66.             facebookComposer.addURL(NSURL(string: "http://www.facebook.com/iswiftbr"))
  67.            
  68.             self.presentViewController(facebookComposer, animated: true, completion: nil)
  69.         }
  70.        
  71.         let cancelAction = UIAlertAction(title: "Cancelar", style: .Cancel, handler: nil)
  72.        
  73.         shareMenu.addAction(facebookAction)
  74.         shareMenu.addAction(cancelAction)
  75.        
  76.         self.presentViewController(shareMenu, animated: true, completion: nil)
  77.        
  78.     }
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top