这个任务已经很老了,已经解决了,但是即使阅读了SO上的所有其他答案,我也无法解决。 我要生成图像,然后将Instagram图像加载到筛选器屏幕中以打开Instagram。没有“打开方式”菜单。我想直接转到Instagram应用。
代码如下:
@objc func share() {
let fileManager = FileManager.default
do {
let documentDirectory =
try fileManager.url(
for: .documentDirectory, in: .userDomainMask,
appropriateFor: nil, create: true)
let fileURL = documentDirectory.appendingPathComponent("challenge.igo")
if let imageData = theImage.jpegData(compressionQuality: 0.5) {
try imageData.write(to: fileURL)
DLog(message: "file written to \(fileURL)")
let dic = UIDocumentInteractionController(url: fileURL)
dic.delegate = self
dic.uti = "com.instagram.exclusivegram"
let res = dic.presentPreview(animated: false)
DLog(message: "presentPreview result \(res)")
}
} catch {
DLog(message: "\(error)")
}
}
我还实现了协议UIDocumentInteractionControllerDelegate
:
extension ICShareController: UIDocumentInteractionControllerDelegate {
func documentInteractionControllerViewControllerForPreview() -> UIViewController {
return self
}
}
但是,presentPreview
函数总是返回false
并且没有打开预览。
我该怎么办?