How to open mail app from Swift

前端 未结 15 1274
被撕碎了的回忆
被撕碎了的回忆 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:38

    You can use simple mailto: links in iOS to open the mail app.

    let email = "foo@bar.com"
    if let url = URL(string: "mailto:\(email)") {
      if #available(iOS 10.0, *) {
        UIApplication.shared.open(url)
      } else {
        UIApplication.shared.openURL(url)
      }    
    }
    

提交回复
热议问题