我想在instagram上共享应用程序,图像和文本的链接是否无法在instagram上显示预填充文本?是否可以通过iOS应用在instagram上共享链接。以下是我的快速代码,请建议我。图片分享成功,如何与文字分享?
以下代码:
import UIKit
class ViewController: UIViewController,UIDocumentInteractionControllerDelegate {
private let documentInteractionController = UIDocumentInteractionController()
private let kInstagramURL = "instagram://"
private let kUTI = "com.instagram.photo" //"com.instagram.exclusivegram"
private let kfileNameExtension = "instagram.ig"//"instagram.igo"
private let kAlertViewTitle = "Error"
private let kAlertViewMessage = "Please install the Instagram application"
var imageInstagram = UIImage()
let instagramCaption = String()
func shareToInstaGram() {
let img = UIImage(named: "Logo")
imageInstagram = img!
let instagramURL = NSURL(string: kInstagramURL)
if UIApplication.shared.canOpenURL(instagramURL! as URL) {
let jpgPath = (NSTemporaryDirectory() as NSString).appendingPathComponent(kfileNameExtension)
do {
try imageInstagram.jpegData(compressionQuality: 0.75)?.write(to: URL(fileURLWithPath: jpgPath), options: .atomic)
} catch {
print(error)
}
let rect = CGRect.zero
let fileURL = NSURL.fileURL(withPath: jpgPath)
documentInteractionController.url = fileURL
documentInteractionController.delegate = self
documentInteractionController.uti = kUTI
documentInteractionController.annotation = ["InstagramCaption": "desTitl"]
documentInteractionController.presentOpenInMenu(from: rect, in: view, animated: true)
}
}
}
有人可以向我解释如何与图片共享文本。任何帮助将不胜感激。
提前感谢。
使用UIActivityViewController
将您的图片和文字发布在任何已安装的社交媒体应用上。