ios: mailto url open
This commit is contained in:
parent
af59178318
commit
23ca901f14
@ -36,11 +36,14 @@ struct CreateSimpleXAddress: View {
|
||||
shareQRCodeButton(userAddress)
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
if MFMailComposeViewController.canSendMail() {
|
||||
Spacer()
|
||||
Spacer()
|
||||
|
||||
if MFMailComposeViewController.canSendMail() {
|
||||
shareViaEmailButton(userAddress)
|
||||
.frame(maxWidth: .infinity)
|
||||
} else {
|
||||
shareViaEmailToButton(userAddress)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
@ -170,6 +173,15 @@ struct CreateSimpleXAddress: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func shareViaEmailToButton(_ userAddress: UserContactLink) -> some View {
|
||||
Button {
|
||||
UserAddressView.shareUserAddressViaMailTo(userAddress)
|
||||
} label: {
|
||||
Label("Invite friends", systemImage: "envelope")
|
||||
.font(.title2)
|
||||
}
|
||||
}
|
||||
|
||||
private func continueButton() -> some View {
|
||||
Button {
|
||||
withAnimation {
|
||||
@ -190,14 +202,14 @@ struct SendAddressMailView: View {
|
||||
var userAddress: UserContactLink
|
||||
|
||||
var body: some View {
|
||||
let messageBody = """
|
||||
let messageBody = NSLocalizedString("""
|
||||
<p>Hi!</p>
|
||||
<p><a href="\(userAddress.connReqContact)">Connect to me via SimpleX Chat</a></p>
|
||||
"""
|
||||
""", comment: "")
|
||||
MailView(
|
||||
isShowing: self.$showMailView,
|
||||
result: $mailViewResult,
|
||||
subject: "Let's talk in SimpleX Chat",
|
||||
subject: NSLocalizedString("Let's talk in SimpleX Chat", comment: ""),
|
||||
messageBody: messageBody
|
||||
)
|
||||
}
|
||||
|
@ -192,9 +192,13 @@ struct UserAddressView: View {
|
||||
Section {
|
||||
QRCode(uri: userAddress.connReqContact)
|
||||
shareQRCodeButton(userAddress)
|
||||
|
||||
if MFMailComposeViewController.canSendMail() {
|
||||
shareViaEmailButton(userAddress)
|
||||
} else {
|
||||
shareViaEmailToButton(userAddress)
|
||||
}
|
||||
|
||||
shareWithContactsButton()
|
||||
autoAcceptToggle()
|
||||
learnMoreButton()
|
||||
@ -286,6 +290,16 @@ struct UserAddressView: View {
|
||||
}
|
||||
}
|
||||
|
||||
private func shareViaEmailToButton(_ userAddress: UserContactLink) -> some View {
|
||||
Button {
|
||||
UserAddressView.shareUserAddressViaMailTo(userAddress)
|
||||
} label: {
|
||||
settingsRow("envelope") {
|
||||
Text("Invite friends")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func autoAcceptToggle() -> some View {
|
||||
settingsRow("checkmark") {
|
||||
Toggle("Auto-accept", isOn: $aas.enable)
|
||||
@ -434,6 +448,36 @@ struct UserAddressView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func shareUserAddressViaMailTo(_ userAddress: UserContactLink) {
|
||||
guard
|
||||
let subject = String(format: NSLocalizedString("Let's talk in SimpleX Chat", comment: "")).addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
|
||||
let addressStr = userAddress.connReqContact.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed.subtracting(CharacterSet(charactersIn: "&"))),
|
||||
let bodyWithoutAddress = (String(format: NSLocalizedString("Hi!\nConnect to me via SimpleX Chat:", comment: "")) + " ").addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
|
||||
else { return }
|
||||
|
||||
let body = bodyWithoutAddress + addressStr
|
||||
|
||||
let gmailUrl = URL(string: "googlegmail://co?subject=\(subject)&body=\(body)")
|
||||
let outlookUrl = URL(string: "ms-outlook://compose?subject=\(subject)&body=\(body)")
|
||||
let yahooUrl = URL(string: "ymail://mail/compose?subject=\(subject)&body=\(body)")
|
||||
let sparkUrl = URL(string: "readdle-spark://compose?subject=\(subject)&body=\(body)")
|
||||
var selectedUrl: URL
|
||||
|
||||
if let gmailUrl = gmailUrl, UIApplication.shared.canOpenURL(gmailUrl) {
|
||||
selectedUrl = gmailUrl
|
||||
} else if let outlookUrl = outlookUrl, UIApplication.shared.canOpenURL(outlookUrl) {
|
||||
selectedUrl = outlookUrl
|
||||
} else if let yahooUrl = yahooUrl, UIApplication.shared.canOpenURL(yahooUrl) {
|
||||
selectedUrl = yahooUrl
|
||||
} else if let sparkUrl = sparkUrl, UIApplication.shared.canOpenURL(sparkUrl) {
|
||||
selectedUrl = sparkUrl
|
||||
} else {
|
||||
return
|
||||
}
|
||||
|
||||
UIApplication.shared.open(selectedUrl, options: [:])
|
||||
}
|
||||
}
|
||||
|
||||
struct UserAddressView_Previews: PreviewProvider {
|
||||
|
@ -2,6 +2,13 @@
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>LSApplicationQueriesSchemes</key>
|
||||
<array>
|
||||
<string>googlegmail</string>
|
||||
<string>ms-outlook</string>
|
||||
<string>readdle-spark</string>
|
||||
<string>ymail</string>
|
||||
</array>
|
||||
<key>BGTaskSchedulerPermittedIdentifiers</key>
|
||||
<array>
|
||||
<string>chat.simplex.app.receive</string>
|
||||
|
Loading…
Reference in New Issue
Block a user