使用 activityController 共享多个图像和文本不起作用
Sharing multiple images AND text using activityController is not working
我正在制作一个销售应用程序,用于为我的公司将图表作为带有文本的图像通过电子邮件发送,但我的应用程序出现了问题。
由于某些原因,我无法同时发送多张图片和文字,激活下面的代码后,只会发送文字。
我检查了三次,图像不是零,我可以共享文本、单独的多张图像或文本和一张图像就可以了。
此外,我只发送两张图片,这仅适用于 phone 版本。
func EmailMultipleImages(imageArray: [UIImage], emailSubject: String, emailBodyText : String) {
print("Image array \(imageArray.count)")
do {
let shareContent: [Any] = [imageArray, emailBodyText]
//Multiple images alone
//let shareContent: [Any] = [imageArray]
//Text alone
//let shareContent: [Any] = [emailBodyText]
//One image and text
//let shareContent: [Any] = [imageArray[0], emailBodyText]
let activityController = UIActivityViewController(activityItems: shareContent, applicationActivities: nil)
activityController.setValue(emailSubject, forKey: "Subject")
viewController!.present(activityController, animated: true, completion: nil)
}
catch {
print("Error print mulitple images \(error)")
}
}
将该数组设为平面对象,它应该可以工作。
示例:
func share() {
let activityItems = [
"Title",
"Body",
UIImage(systemName: "keyboard")!,
UIImage(systemName: "square.and.arrow.up")!
] as [Any]
let vc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
vc.setValue("Testing", forKey: "Subject")
self.present(vc, animated: true, completion: nil)
}
输出:
我正在制作一个销售应用程序,用于为我的公司将图表作为带有文本的图像通过电子邮件发送,但我的应用程序出现了问题。
由于某些原因,我无法同时发送多张图片和文字,激活下面的代码后,只会发送文字。
我检查了三次,图像不是零,我可以共享文本、单独的多张图像或文本和一张图像就可以了。
此外,我只发送两张图片,这仅适用于 phone 版本。
func EmailMultipleImages(imageArray: [UIImage], emailSubject: String, emailBodyText : String) {
print("Image array \(imageArray.count)")
do {
let shareContent: [Any] = [imageArray, emailBodyText]
//Multiple images alone
//let shareContent: [Any] = [imageArray]
//Text alone
//let shareContent: [Any] = [emailBodyText]
//One image and text
//let shareContent: [Any] = [imageArray[0], emailBodyText]
let activityController = UIActivityViewController(activityItems: shareContent, applicationActivities: nil)
activityController.setValue(emailSubject, forKey: "Subject")
viewController!.present(activityController, animated: true, completion: nil)
}
catch {
print("Error print mulitple images \(error)")
}
}
将该数组设为平面对象,它应该可以工作。
示例:
func share() {
let activityItems = [
"Title",
"Body",
UIImage(systemName: "keyboard")!,
UIImage(systemName: "square.and.arrow.up")!
] as [Any]
let vc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
vc.setValue("Testing", forKey: "Subject")
self.present(vc, animated: true, completion: nil)
}
输出: