carekit-apple / CareKit

CareKit is an open source software framework for creating apps that help people better understand and manage their health.
https://www.researchandcare.org
Other
2.4k stars 445 forks source link

Sending Email to Contact Not Working when Apple Mail is uninstalled #469

Open MihirJoe opened 4 years ago

MihirJoe commented 4 years ago

When using the contact feature, the email functionality doesn't seem to work on the simulator and even when I run the app on my iPhone. For reference, the code is similar to the OCKSample app:

contact1.emailAddresses = [OCKLabeledValue(label: CNLabelEmailiCloud, value: "janedaniels@icloud.com")]

After doing some testing of my own, I figured out that the Simulator doesn't have built in functionality for sending emails. When I went through my iPhone, I reinstalled my native Apple mail app and the email functionality worked perfectly. That being said, is there any way to be able to still send emails using the OCKContactViewController even though the user may not have the Apple Mail app installed?

Thanks!

gavirawson-apple commented 4 years ago

Hello @MihirJoe! What is your use case for wanting to send an email through the simulator? Is it for testing? Or for sending an email using a custom email client?

If either of those are the case, you can override a method in the contact view controller that gets triggered when the email button is tapped:

override open func contactView(_ contactView: UIView & OCKContactDisplayable, senderDidInitiateEmail sender: Any?) {
    // Perform custom logic here
}
MihirJoe commented 4 years ago

Hello @gavirawson-apple, thank you for the response! I'm not necessarily trying to use email within the simulator because I can just run the app on my iPhone, but I know that with the more recent iOS versions, you can change which email client you use and I just thought that if someone doesn't use the built-in email client, then they wouldn't be able to reach out to the primary care provider via email. However, I do have the phone number option in my Contacts List View Controller and will probably add a messaging feature.

urbanintell commented 3 years ago

How can I use senderDidInitiateEmail to include an OCKCartesianChartViewController in the email? I'm thinking something like..

    func contactView(_ contactView: UIView & OCKContactDisplayable, senderDidInitiateEmail sender: Any?) {
        print("sending email....")

      let recipient =   CareKitManager.synchronizedStoreManager.store.fetchAnyContact(withID: <#T##String#>, callbackQueue: <#T##DispatchQueue#>, completion: <#T##OCKResultClosure<OCKAnyContact>##OCKResultClosure<OCKAnyContact>##(Result<OCKAnyContact, OCKStoreError>) -> Void#>)

        let chart = InsightsChart
        let chartHtml = Somefunc(chart) -> return chart html

        let mailViewController = MFMailComposeViewController()
        mailViewController.setMessageBody(chartHtml, isHTML: true)
        mailViewController.mailComposeDelegate = self
        mailViewController.setToRecipients([recipient])
        self.present(mailViewController, animated: true, completion: nil)
    }

however it appears as though OCKDocument does not exist anymore. What is the current way to approach this ?

gavirawson-apple commented 3 years ago

CareKit 2.0 no longer supports converting a chart to a PDF. However, you can query for the relevant data in the store and write out custom logic to convert the data to a visual presentation in a PDF.

If you do implement the feature, the community would be thrilled if you submitted a PR!

erik-apple commented 3 years ago

@urbanintell Creating a PDF as Gavi suggested has become fairly straight forward. You can also look at #408, where we provide some sample code that shows how to do just that.