-
Notifications
You must be signed in to change notification settings - Fork 9
Attachment support #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate { | |
| * Configure BugShaker with an array of email recipients (required) | ||
| * and an optional custom subject line to use for all bug reports. | ||
| */ | ||
| BugShaker.configure(to: [ "example@email.com" ], subject: "Bug Report", body: "Hi Developers, I am reporting a bug where...") | ||
| let fileName = "testFile.txt" | ||
| let fileContent = "This is the content of the file." | ||
| let file = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0].appendingPathComponent(fileName) | ||
|
|
||
| try! fileContent.write(to: file, atomically: true, encoding: .utf8) | ||
|
|
||
| let attachment = BugShaker.MailAttachment(data: try! Data(contentsOf: file), mimeType: "text/plain", fileName: fileName) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Force Try Violation: Force tries should be avoided. (force_try) |
||
|
|
||
| BugShaker.configure(to: [ "example@email.com" ], subject: "Bug Report", body: "Hi Developers, I am reporting a bug where...", attachments: [attachment]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line Length Violation: Line should be 120 characters or less: currently 156 characters (line_length) |
||
|
|
||
| return true | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,20 @@ | ||
| PODS: | ||
| - Nimble (8.0.1) | ||
| - Quick (2.1.0) | ||
| - Nimble (8.0.4) | ||
| - Quick (2.2.0) | ||
|
|
||
| DEPENDENCIES: | ||
| - Nimble | ||
| - Quick | ||
|
|
||
| SPEC REPOS: | ||
| https://github.com/cocoapods/specs.git: | ||
| https://github.com/CocoaPods/Specs.git: | ||
| - Nimble | ||
| - Quick | ||
|
|
||
| SPEC CHECKSUMS: | ||
| Nimble: 45f786ae66faa9a709624227fae502db55a8bdd0 | ||
| Quick: 4be43f6634acfa727dd106bdf3929ce125ffa79d | ||
| Nimble: 18d5360282923225d62b09d781f63abc1a0111fc | ||
| Quick: 7fb19e13be07b5dfb3b90d4f9824c855a11af40e | ||
|
|
||
| PODFILE CHECKSUM: 670d452da847b95b324bec94807b831678d715b0 | ||
|
|
||
| COCOAPODS: 1.7.1 | ||
| COCOAPODS: 1.8.4 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,19 @@ final public class BugShaker { | |
| static var recipients: [String]? | ||
| static var subject: String? | ||
| static var body: String? | ||
| static var attachments: (() -> [MailAttachment])? | ||
| } | ||
|
|
||
| public struct MailAttachment { | ||
| let data: Data | ||
| let mimeType: String | ||
| let fileName: String | ||
|
|
||
| public init(data: Data, mimeType: String, fileName: String) { | ||
| self.data = data | ||
| self.mimeType = mimeType | ||
| self.fileName = fileName | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Configuration | ||
|
|
@@ -30,10 +43,11 @@ final public class BugShaker { | |
| - subject: Custom subject line to use for the report email. | ||
| - body: Custom email body (plain text). | ||
| */ | ||
| public class func configure(to recipients: [String], subject: String?, body: String? = nil) { | ||
| public class func configure(to recipients: [String], subject: String?, body: String? = nil, attachments: (() -> [MailAttachment])? = nil) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Line Length Violation: Line should be 120 characters or less: currently 143 characters (line_length) |
||
| Config.recipients = recipients | ||
| Config.subject = subject | ||
| Config.body = body | ||
| Config.attachments = attachments | ||
| } | ||
|
|
||
| } | ||
|
|
@@ -47,7 +61,10 @@ extension UIViewController: MFMailComposeViewControllerDelegate { | |
| } | ||
|
|
||
| override open func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) { | ||
| guard BugShaker.isEnabled && motion == .motionShake else { return } | ||
| guard BugShaker.isEnabled && motion == .motionShake else { | ||
| next?.motionEnded(motion, with: event) | ||
| return | ||
| } | ||
|
|
||
| let cachedScreenshot = captureScreenshot() | ||
|
|
||
|
|
@@ -127,6 +144,10 @@ extension UIViewController: MFMailComposeViewControllerDelegate { | |
| if let screenshot = screenshot, let screenshotJPEG = screenshot.jpegData(compressionQuality: CGFloat(1.0)) { | ||
| mailComposer.addAttachmentData(screenshotJPEG, mimeType: "image/jpeg", fileName: "screenshot.jpeg") | ||
| } | ||
|
|
||
| BugShaker.Config.attachments?().forEach { | ||
| mailComposer.addAttachmentData($0.data, mimeType: $0.mimeType, fileName: $0.fileName) | ||
| } | ||
|
|
||
| present(mailComposer, animated: true, completion: nil) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force Try Violation: Force tries should be avoided. (force_try)