Reputation: 300
I am making a sales app to email charts as images with text for my company, but I am having a problem with my app.
For some reason I can't send multiple images and text together, when the code below is activated, only the text is sent.
I triple checked and the images are NOT nil and I can share text, multiple images alone or text and a single image just fine.
Furthermore I am only sending two images and this is just for the phone version alone.
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)")
}
}
Upvotes: 1
Views: 1909
Reputation: 3714
Make that array a flat object and it should work.
example:
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)
}
Output:
Upvotes: 2