How to open mail app from Swift

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

    For those of us still lagging behind on Swift 2.3 here is Gordon's answer in our syntax:

    let email = "foo@bar.com"
    if let url = NSURL(string: "mailto:\(email)") {
       UIApplication.sharedApplication().openURL(url)
    }
    

提交回复
热议问题