Skip to content

Commit

Permalink
Merge pull request wikimedia#3944 from wikimedia/T269042
Browse files Browse the repository at this point in the history
Use user's default mail client when reporting a bug
  • Loading branch information
dempseyatgithub authored May 11, 2021
2 parents dc13ad3 + 84b2c72 commit 0924c07
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Wikipedia.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -4071,7 +4071,7 @@
83F1096323D0D4F6003F3E9E /* ArticlePreviewingDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticlePreviewingDelegate.swift; sourceTree = "<group>"; };
83F1096823D0DB0F003F3E9E /* ViewController+ArticlePreviewing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ViewController+ArticlePreviewing.swift"; sourceTree = "<group>"; };
83F1096D23D0E787003F3E9E /* RandomArticleViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RandomArticleViewController.swift; sourceTree = "<group>"; };
83F1097223D0F115003F3E9E /* HelpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpViewController.swift; sourceTree = "<group>"; };
83F1097223D0F115003F3E9E /* HelpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpViewController.swift; sourceTree = "<group>"; usesTabs = 0; };
83F26B29220B62EC002D87A4 /* SectionEditorButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionEditorButton.swift; sourceTree = "<group>"; };
83FBE96E1F6172ED0026C7EB /* ShareAFactActivityTextItemProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareAFactActivityTextItemProvider.swift; sourceTree = "<group>"; };
83FBE9741F6181E00026C7EB /* ShareAFactActivityImageItemProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareAFactActivityImageItemProvider.swift; sourceTree = "<group>"; };
Expand Down
35 changes: 14 additions & 21 deletions Wikipedia/Code/HelpViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,25 @@ class HelpViewController: SinglePageWebViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}

@objc func sendEmail() {
guard MFMailComposeViewController.canSendMail() else {
WMFAlertManager.sharedInstance.showErrorAlertWithMessage(WMFLocalizedString("no-email-account-alert", value: "Please setup an email account on your device and try again.", comment: "Displayed to the user when they try to send a feedback email, but they have never set up an account on their device"), sticky: false, dismissPreviousAlerts: false)
return
}
let vc = MFMailComposeViewController()
vc.setSubject(HelpViewController.emailSubject)
vc.setToRecipients([HelpViewController.emailAddress])
vc.setMessageBody("\n\n\n\nVersion: \(WikipediaAppUtils.versionedUserAgent())", isHTML: false)
if let data = DDLog.wmf_currentLogFile()?.data(using: .utf8) {
vc.addAttachmentData(data, mimeType: "text/plain", fileName: "Log.txt")
}
vc.mailComposeDelegate = self
present(vc, animated: true)
}


private func setupToolbar() {
enableToolbar()
toolbar.items = [UIBarButtonItem.flexibleSpaceToolbar(), sendEmailToolbarItem, UIBarButtonItem.wmf_barButtonItem(ofFixedWidth: 8)]
setToolbarHidden(false, animated: false)
}
}

@objc func sendEmail() {
let address = HelpViewController.emailAddress
let subject = HelpViewController.emailSubject
let body = "\n\n\n\nVersion: \(WikipediaAppUtils.versionedUserAgent())"
let mailto = "mailto:\(address)?subject=\(subject)&body=\(body)".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)

guard let encodedMailto = mailto, let mailtoURL = URL(string: encodedMailto), UIApplication.shared.canOpenURL(mailtoURL) else {
WMFAlertManager.sharedInstance.showErrorAlertWithMessage(WMFLocalizedString("no-email-account-alert", value: "Please setup an email account on your device and try again.", comment: "Displayed to the user when they try to send a feedback email, but they have never set up an account on their device"), sticky: false, dismissPreviousAlerts: false)
return
}

extension HelpViewController: MFMailComposeViewControllerDelegate {
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
dismiss(animated: true)
UIApplication.shared.open(mailtoURL)
}

}
4 changes: 4 additions & 0 deletions Wikipedia/Experimental-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
</dict>
Expand Down
4 changes: 4 additions & 0 deletions Wikipedia/Local-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<!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>mailto</string>
</array>
<key>BGTaskSchedulerPermittedIdentifiers</key>
<array>
<string>org.wikimedia.wikipedia.appRefresh</string>
Expand Down
4 changes: 4 additions & 0 deletions Wikipedia/Staging-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
</dict>
Expand Down
4 changes: 4 additions & 0 deletions Wikipedia/User Testing-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
</dict>
Expand Down
4 changes: 4 additions & 0 deletions Wikipedia/Wikipedia-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<true/>
</dict>
Expand Down

0 comments on commit 0924c07

Please sign in to comment.