Compare commits

...

1 Commits

Author SHA1 Message Date
Stanislav Dmitrenko
23ca901f14 ios: mailto url open 2023-05-04 07:03:25 -07:00
3 changed files with 69 additions and 6 deletions

View File

@@ -36,11 +36,14 @@ struct CreateSimpleXAddress: View {
shareQRCodeButton(userAddress) shareQRCodeButton(userAddress)
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
Spacer()
if MFMailComposeViewController.canSendMail() { if MFMailComposeViewController.canSendMail() {
Spacer()
shareViaEmailButton(userAddress) shareViaEmailButton(userAddress)
.frame(maxWidth: .infinity) .frame(maxWidth: .infinity)
} else {
shareViaEmailToButton(userAddress)
.frame(maxWidth: .infinity)
} }
Spacer() 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 { private func continueButton() -> some View {
Button { Button {
withAnimation { withAnimation {
@@ -190,14 +202,14 @@ struct SendAddressMailView: View {
var userAddress: UserContactLink var userAddress: UserContactLink
var body: some View { var body: some View {
let messageBody = """ let messageBody = NSLocalizedString("""
<p>Hi!</p> <p>Hi!</p>
<p><a href="\(userAddress.connReqContact)">Connect to me via SimpleX Chat</a></p> <p><a href="\(userAddress.connReqContact)">Connect to me via SimpleX Chat</a></p>
""" """, comment: "")
MailView( MailView(
isShowing: self.$showMailView, isShowing: self.$showMailView,
result: $mailViewResult, result: $mailViewResult,
subject: "Let's talk in SimpleX Chat", subject: NSLocalizedString("Let's talk in SimpleX Chat", comment: ""),
messageBody: messageBody messageBody: messageBody
) )
} }

View File

@@ -40,7 +40,7 @@ struct UserAddressView: View {
} }
} }
} }
var body: some View { var body: some View {
ZStack { ZStack {
if viaCreateLinkView { if viaCreateLinkView {
@@ -192,9 +192,13 @@ struct UserAddressView: View {
Section { Section {
QRCode(uri: userAddress.connReqContact) QRCode(uri: userAddress.connReqContact)
shareQRCodeButton(userAddress) shareQRCodeButton(userAddress)
if MFMailComposeViewController.canSendMail() { if MFMailComposeViewController.canSendMail() {
shareViaEmailButton(userAddress) shareViaEmailButton(userAddress)
} else {
shareViaEmailToButton(userAddress)
} }
shareWithContactsButton() shareWithContactsButton()
autoAcceptToggle() autoAcceptToggle()
learnMoreButton() 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 { private func autoAcceptToggle() -> some View {
settingsRow("checkmark") { settingsRow("checkmark") {
Toggle("Auto-accept", isOn: $aas.enable) 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 { struct UserAddressView_Previews: PreviewProvider {

View File

@@ -2,6 +2,13 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>googlegmail</string>
<string>ms-outlook</string>
<string>readdle-spark</string>
<string>ymail</string>
</array>
<key>BGTaskSchedulerPermittedIdentifiers</key> <key>BGTaskSchedulerPermittedIdentifiers</key>
<array> <array>
<string>chat.simplex.app.receive</string> <string>chat.simplex.app.receive</string>