Sharing a image from UIImageView
using UIActivityViewController
?
I am trying to share a image using UIActivityViewController
, but I get error:
func shareIMG(){
let activityItems = [self.imageView.image]
let avc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
self.presentViewController(avc, animated: true, completion: nil)
}
Error message:
Cannot find an initializer for type 'UIActivityViewController' that accepts an argument list of type '(activityItems: [UIImage?], applicationActivities: nil)'
Any ideas?
let activityItem: [AnyObject] = [self.imageView.image as! AnyObject]
let avc = UIActivityViewController(activityItems: activityItem as [AnyObject], applicationActivities: nil)
self.presentViewController(avc, animated: true, completion: nil)
Note : The above code tested in Xcode 6.3 simulator
Just create a button and it's action. And install the button's action like this.
Note: You have to log in your facebook or twitter by going to setting. Then do like this.
@IBAction func onShareTouched(sender: AnyObject) {
print("share")
let myShare = "My beautiful photo! <3 <3"
let image: UIImage = UIImage(named: "yourImageNameHere")
let shareVC: UIActivityViewController = UIActivityViewController(activityItems: [(image), myShare], applicationActivities: nil)
self.presentViewController(shareVC, animated: true, completion: nil)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With