How to open mail app from Swift

前端 未结 15 1282
被撕碎了的回忆
被撕碎了的回忆 2020-11-30 20:18

Im working on a simple swift app where the user inputs an email address and presses a button which opens the mail app, with the entered address in the address bar. I know ho

15条回答
  •  独厮守ぢ
    2020-11-30 20:48

    For Swift 4.2+ and iOS 9+

    let appURL = URL(string: "mailto:TEST@EXAMPLE.COM")!
    
    if #available(iOS 10.0, *) {
        UIApplication.shared.open(appURL, options: [:], completionHandler: nil)
    } else {
        UIApplication.shared.openURL(appURL)
    }
    

    Replace TEST@EXAMPLE.COM with your desired email address.

提交回复
热议问题