From f1f2eb918ebf420c6289b652812c660341721d5e Mon Sep 17 00:00:00 2001 From: Fabio Tacke Date: Fri, 21 Jun 2019 09:48:24 +0200 Subject: [PATCH 1/3] Pass motion event to next responder if not being handled --- Sources/BugShaker.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/BugShaker.swift b/Sources/BugShaker.swift index 679edc3..0175e5a 100644 --- a/Sources/BugShaker.swift +++ b/Sources/BugShaker.swift @@ -47,7 +47,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() From 91012f2ae5b174252bc6c4f8fe1bc7423156cf7c Mon Sep 17 00:00:00 2001 From: Fabio Tacke Date: Tue, 29 Oct 2019 10:37:38 +0100 Subject: [PATCH 2/3] Add support for adding attachments --- Example/Sources/AppDelegate.swift | 10 +++++++++- Podfile.lock | 12 ++++++------ Sources/BugShaker.swift | 20 +++++++++++++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/Example/Sources/AppDelegate.swift b/Example/Sources/AppDelegate.swift index 5266522..6816e10 100644 --- a/Example/Sources/AppDelegate.swift +++ b/Example/Sources/AppDelegate.swift @@ -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) + + BugShaker.configure(to: [ "example@email.com" ], subject: "Bug Report", body: "Hi Developers, I am reporting a bug where...", attachments: [attachment]) return true } diff --git a/Podfile.lock b/Podfile.lock index 1f565fe..6dd3946 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -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 diff --git a/Sources/BugShaker.swift b/Sources/BugShaker.swift index 0175e5a..879ca95 100644 --- a/Sources/BugShaker.swift +++ b/Sources/BugShaker.swift @@ -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] = []) { Config.recipients = recipients Config.subject = subject Config.body = body + Config.attachments = attachments } } @@ -130,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") } + + for attachment in BugShaker.Config.attachments { + mailComposer.addAttachmentData(attachment.data, mimeType: attachment.mimeType, fileName: attachment.fileName) + } present(mailComposer, animated: true, completion: nil) } From d687081c99881581ad73fcf9b0bf4f18b6f054df Mon Sep 17 00:00:00 2001 From: Fabio Tacke Date: Wed, 3 Jun 2020 16:36:22 +0200 Subject: [PATCH 3/3] Enable dynamic attachment generation --- Sources/BugShaker.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/BugShaker.swift b/Sources/BugShaker.swift index 879ca95..36bd071 100644 --- a/Sources/BugShaker.swift +++ b/Sources/BugShaker.swift @@ -18,7 +18,7 @@ final public class BugShaker { static var recipients: [String]? static var subject: String? static var body: String? - static var attachments: [MailAttachment] = [] + static var attachments: (() -> [MailAttachment])? } public struct MailAttachment { @@ -43,7 +43,7 @@ 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, attachments: [MailAttachment] = []) { + public class func configure(to recipients: [String], subject: String?, body: String? = nil, attachments: (() -> [MailAttachment])? = nil) { Config.recipients = recipients Config.subject = subject Config.body = body @@ -145,8 +145,8 @@ extension UIViewController: MFMailComposeViewControllerDelegate { mailComposer.addAttachmentData(screenshotJPEG, mimeType: "image/jpeg", fileName: "screenshot.jpeg") } - for attachment in BugShaker.Config.attachments { - mailComposer.addAttachmentData(attachment.data, mimeType: attachment.mimeType, fileName: attachment.fileName) + BugShaker.Config.attachments?().forEach { + mailComposer.addAttachmentData($0.data, mimeType: $0.mimeType, fileName: $0.fileName) } present(mailComposer, animated: true, completion: nil)