I would like to make Facebook share button on my app that shares the image that is loaded from the UIImageview. I cannot figure out how to do it.. There is option to add the text on Facebook share window, but can't add the image. Please help.
import UIKit
import Social
class ViewController: UIViewController {
@IBOutlet weak var saveButtonVar: UIButton!
@IBOutlet weak var image: UIImageView!
@IBAction func facebookBtn(sender: AnyObject) {
var facebookBtn : SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
facebookBtn.setInitialText("I am sharing my motivation with you!")
facebookBtn.addImage(UIImage(named: "motImg")) //????
self.presentViewController(facebookBtn, animated: true, completion: nil)
}
@IBAction func twitterBtn(sender: AnyObject) {
}
@IBAction func saveButton(sender: AnyObject) {
UIImageWriteToSavedPhotosAlbum(image.image, nil, nil, nil)
let alertController = UIAlertController(title: "Image Saved!", message:
"", preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default,handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
@IBAction func button(sender: AnyObject) {
load_image("https://dl.dropboxusercontent.com/u/26347781/Images/Image\(arc4random_uniform(17) + 1).jpg")
saveButtonVar.hidden = false
}
func load_image(urlString:String)
{
var imgURL: NSURL = NSURL(string: urlString)!
let request: NSURLRequest = NSURLRequest(URL: imgURL)
NSURLConnection.sendAsynchronousRequest(
request, queue: NSOperationQueue.mainQueue(),
completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
if error == nil {
self.image.image = UIImage(data: data)
}
})
}
override func viewDidLoad() {
super.viewDidLoad()
saveButtonVar.hidden = true
image.image = UIImage(named: "motImg")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}