Does anyone know of a way to send an email from th...
# multiplatform
j
Does anyone know of a way to send an email from the iOS source set in KMM? I've built out the
MFMailComposeViewController
but am unsure how to present it to the user. I've been experimenting and tried:
Copy code
val rootViewController = UIApplication.sharedApplication().delegate?.window?.rootViewController()
rootViewController?.presentViewController(mfMailComposeViewController, animated = true, null)
But it fails when grabbing the window. I'm not super familiar with iOS concepts so I'm sure there is some fundamental knowledge missing here.
Looks like it may be better to construct the
mailto:
URL and have the application open the URL without messing with views
r
I spent the whole day trying to make this work and came to the same conclusion that
mailto
is the way to go. Here in a full code snippet.
Copy code
actual fun sendEmail(onError: () -> Unit) {
    val mailtoString = "mailto:${iosSupportEmail}?subject=Support for Papely ${getBuildVersion()}"
    val mailtoUrl = NSURL(string = mailtoString)
    if (UIApplication.sharedApplication.canOpenURL(mailtoUrl)) {
        UIApplication.sharedApplication.openURL(mailtoUrl)
    } else {
        onError.invoke()
    }
}
125 Views