Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Example/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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)


let attachment = BugShaker.MailAttachment(data: try! Data(contentsOf: file), mimeType: "text/plain", fileName: fileName)

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)
Line Length Violation: Line should be 120 characters or less: currently 124 characters (line_length)


BugShaker.configure(to: [ "example@email.com" ], subject: "Bug Report", body: "Hi Developers, I am reporting a bug where...", attachments: [attachment])

Choose a reason for hiding this comment

The 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
}
Expand Down
12 changes: 6 additions & 6 deletions Podfile.lock
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
25 changes: 23 additions & 2 deletions Sources/BugShaker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {

Choose a reason for hiding this comment

The 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
}

}
Expand All @@ -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()

Expand Down Expand Up @@ -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)
}
Expand Down