Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import FBSDKLoginKit
- import FBSDKShareKit
- import FBSDKMessengerShareKit
- import Social
- class ViewController: UIViewController, UITextFieldDelegate {
- private let URL = NSURL(string: "http://graph.facebook.com/me")!
- let loginbutton = FBSDKLoginButton()
- override func viewDidLoad() {
- super.viewDidLoad()
- loginbutton.center = self.view.center
- self.view.addSubview(loginbutton)
- }
- @IBAction func abrirPagina(sender: AnyObject) {
- let url: NSURL = NSURL(string: "http://www.facebook.com/iswiftbr")!
- UIApplication.sharedApplication().openURL(url)
- }
- @IBAction func shareDialog(sender: AnyObject) {
- let content = FBSDKShareLinkContent()
- content.contentURL = NSURL(string: "http://www.facebook.com/iswiftbr")
- FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)
- FBSDKMessageDialog.showWithContent(content, delegate: nil)
- let dialogo = FBSDKShareDialog()
- dialogo.fromViewController = self
- dialogo.mode = FBSDKShareDialogMode.ShareSheet
- dialogo.show()
- FBSDKShareAPI.shareWithContent(content, delegate: nil)
- }
- @IBAction func share(sender: AnyObject) {
- let shareMenu = UIAlertController(title: "Compartilhar", message: "", preferredStyle: .ActionSheet)
- let facebookAction = UIAlertAction(title: "Facebook", style: .Default) { (action) -> Void in
- guard SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook) else {
- 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)
- alertMessage.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
- self.presentViewController(alertMessage, animated: true, completion: nil)
- return
- }
- let facebookComposer = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
- facebookComposer.setInitialText("Texto Inicial")
- facebookComposer.addURL(NSURL(string: "http://www.facebook.com/iswiftbr"))
- self.presentViewController(facebookComposer, animated: true, completion: nil)
- }
- let cancelAction = UIAlertAction(title: "Cancelar", style: .Cancel, handler: nil)
- shareMenu.addAction(facebookAction)
- shareMenu.addAction(cancelAction)
- self.presentViewController(shareMenu, animated: true, completion: nil)
- }
- }
Add Comment
Please, Sign In to add comment