gpt4 book ai didi

ios - Swift Facebook 分享 UIImageview 图片

转载 作者:行者123 更新时间:2023-11-28 07:05:18 45 4
gpt4 key购买 nike

我想在我的应用程序上创建 Facebook 共享按钮,用于共享从 UIImageview 加载的图像。我不知道该怎么做。可以选择在 Facebook 共享窗口中添加文本,但无法添加图像。请帮忙。

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.
}



}

最佳答案

swift 4

集成 FacebookShare sdk。

人们可以使用共享对话框或自定义界面将您应用中的照片分享到 Facebook:

-照片的大小必须小于 12MB。

-人们需要安装原生 Facebook for iOS 应用程序,版本 7.0 或更高

@IBAction func facebookBtn(sender: AnyObject) {
let shareImage = SharePhoto()
shareImage.image = imageView.image //Image from your imageview
shareImage.isUserGenerated = true

let content = SharePhotoContent()
content.photos = [shareImage]

let sharedDialoge = ShareDialog()
sharedDialoge.shareContent = content

sharedDialoge.fromViewController = self
sharedDialoge.mode = .automatic


if(sharedDialoge.canShow)
{
sharedDialoge.show()
}
else
{
print("Install Facebook client app to share image")
}
}

关于ios - Swift Facebook 分享 UIImageview 图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30812602/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com