I have an issue with the UIActivityViewController
.
In my app, I have a screen with a feedback section, and I want to show the activity popup when the user presses the "send feedback" button and then displays the correct subject, sender, and body message after choosing the mail app.
Expected result:
- Show the activity popup.
- If the mail app is chosen(default ios mail app, Gmail, spark, etc.), show the correct recipe, subject, and mail body text.
My code shows the activity popup, but if you press any mail apps, the recipe, the subject, and the body text are empty.
Here is my code example:
@objc func buttonClicked() {
button.setTitleColor(.gray, for: .normal)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
self.button.setTitleColor(.white, for: .normal)
}
// Additional actions or logic when the button is clicked
let feedbackText = "feedback"
let userId = "userId"
let subject = "subject"
guard let currentUserEmail = getModule(UserProfileService.self).currentUser?.emailAddress else {
return
}
// Create the activity view controller
let activityViewController = UIActivityViewController(activityItems: [feedbackText], applicationActivities: nil)
// Exclude all apps except for email
activityViewController.excludedActivityTypes = [
.addToReadingList,
.airDrop,
.assignToContact,
.copyToPasteboard,
.message,
.openInIBooks,
.postToFacebook,
.postToFlickr,
.postToTencentWeibo,
.postToTwitter,
.postToVimeo,
.postToWeibo,
.print,
.saveToCameraRoll
]
activityViewController.completionWithItemsHandler = { [weak self] (activityType, completed, _, _) in
if completed, activityType == .mail {
if MFMailComposeViewController.canSendMail() {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface
composeVC.setToRecipients([UserProfileViewController.feedbackEmail])
composeVC.setSubject("subject")
composeVC.setMessageBody("message")", isHTML: true)
if let userId = self?.viewModel.userProfileService.currentUser?.id {
let subject = "UserId: \(userId)"
composeVC.setSubject("subject")
}
self?.present(composeVC, animated: true)
}
}
}
present(activityViewController, animated: true, completion: nil)
}