Skip to content

Commit 4284e7f

Browse files
committed
Merge pull request #16 from square/federman/bug_report_additions
Add a mechanism to specify dynamic key-value pairs in the prefill email body of a bug report
2 parents 4c8fedf + 714abd3 commit 4284e7f

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
lines changed

Aardvark.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Aardvark'
3-
s.version = '1.1.3'
3+
s.version = '1.2.0'
44
s.license = 'Apache License, Version 2.0'
55
s.summary = 'Aardvark is a library that makes it dead simple to create actionable bug reports.'
66
s.homepage = 'https://github.com/square/Aardvark'

Bug Reporting/ARKEmailBugReporter.h

+14
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,24 @@
2222
#import <MessageUI/MessageUI.h>
2323

2424

25+
@class ARKEmailBugReporter;
2526
@class ARKLogStore;
2627
@protocol ARKLogFormatter;
2728

2829

2930
NS_ASSUME_NONNULL_BEGIN
3031

3132

33+
@protocol ARKEmailBugReporterEmailBodyAdditionsDelegate <NSObject>
34+
35+
@required
36+
37+
/// Called on the main thread when a bug is filed. The key/value pairs in the returned dictionary will be appended to the bug report below the prefilledEmailBody.
38+
- (nullable NSDictionary *)emailBodyAdditionsForEmailBugReporter:(ARKEmailBugReporter *)emailBugReporter;
39+
40+
@end
41+
42+
3243
/// Composes a bug report that is sent via email.
3344
@interface ARKEmailBugReporter : NSObject <ARKBugReporter>
3445

@@ -40,6 +51,9 @@ NS_ASSUME_NONNULL_BEGIN
4051
/// The email body that will be presented to the user when they compose a report.
4152
@property (nonatomic, copy) NSString *prefilledEmailBody;
4253

54+
/// The email body delegate, responsible for providing key/value pairs to include in the bug report at the time the bug is filed.
55+
@property (nullable, nonatomic, weak) id <ARKEmailBugReporterEmailBodyAdditionsDelegate> emailBodyAdditionsDelegate;
56+
4357
/// The formatter used to prepare the log for entry into an email. Defaults to a vanilla instance of ARKDefaultLogFormatter.
4458
@property (nonatomic) id <ARKLogFormatter> logFormatter;
4559

Bug Reporting/ARKEmailBugReporter.m

+23-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ - (instancetype)init;
6363
@"2. \n"
6464
@"3. \n"
6565
@"\n"
66-
@"System version: %@\n", [[UIDevice currentDevice] systemVersion]];
66+
@"System version: %@", [[UIDevice currentDevice] systemVersion]];
6767

6868
_logFormatter = [ARKDefaultLogFormatter new];
6969
_numberOfRecentErrorLogsToIncludeInEmailBodyWhenAttachmentsAreAvailable = 3;
@@ -182,6 +182,7 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)
182182
NSString *bugTitle = [alertView textFieldAtIndex:0].text;
183183
NSArray *logStores = [self.logStores copy];
184184
NSMapTable *logStoresToLogMessagesMap = [NSMapTable new];
185+
NSDictionary *emailBodyAdditions = [self.emailBodyAdditionsDelegate emailBodyAdditionsForEmailBugReporter:self];
185186

186187
if ([MFMailComposeViewController canSendMail]) {
187188
self.mailComposeViewController = [MFMailComposeViewController new];
@@ -195,7 +196,8 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)
195196

196197
// Only attach data once all log messages have been retrieved.
197198
if (logStoresToLogMessagesMap.count == logStores.count) {
198-
NSMutableString *emailBody = [NSMutableString stringWithFormat:@"%@\n", self.prefilledEmailBody];
199+
NSMutableString *emailBody = [self _prefilledEmailBodyWithEmailBodyAdditions:emailBodyAdditions];
200+
199201
for (ARKLogStore *logStore in logStores) {
200202
NSArray *logMessages = [logStoresToLogMessagesMap objectForKey:logStore];
201203

@@ -245,11 +247,11 @@ - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)
245247

246248
// Only append logs once all log messages have been retrieved.
247249
if (logStoresToLogMessagesMap.count == logStores.count) {
248-
NSMutableString *emailBody = [NSMutableString new];
250+
NSMutableString *emailBody = [self _prefilledEmailBodyWithEmailBodyAdditions:emailBodyAdditions];
251+
249252
for (ARKLogStore *logStore in logStores) {
250253
NSArray *logMessages = [logStoresToLogMessagesMap objectForKey:logStore];
251-
252-
[emailBody appendFormat:@"%@\n%@\n", self.prefilledEmailBody, [self _recentErrorLogMessagesAsPlainText:logMessages count:self.numberOfRecentErrorLogsToIncludeInEmailBodyWhenAttachmentsAreUnavailable]];
254+
[emailBody appendFormat:@"%@\n", [self _recentErrorLogMessagesAsPlainText:logMessages count:self.numberOfRecentErrorLogsToIncludeInEmailBodyWhenAttachmentsAreUnavailable]];
253255
}
254256

255257
NSURL *composeEmailURL = [self _emailURLWithRecipients:@[self.bugReportRecipientEmailAddress] CC:@"" subject:bugTitle body:emailBody];
@@ -368,6 +370,22 @@ - (void)_dismissEmailComposeWindow;
368370
}
369371
}
370372

373+
- (NSMutableString *)_prefilledEmailBodyWithEmailBodyAdditions:(nullable NSDictionary *)emailBodyAdditions;
374+
{
375+
NSMutableString *prefilledEmailBodyWithEmailBodyAdditions = [NSMutableString stringWithFormat:@"%@\n", self.prefilledEmailBody];
376+
377+
if (emailBodyAdditions.count > 0) {
378+
for (NSString *emailBodyAdditionKey in emailBodyAdditions.allKeys) {
379+
[prefilledEmailBodyWithEmailBodyAdditions appendFormat:@"%@: %@\n", emailBodyAdditionKey, emailBodyAdditions[emailBodyAdditionKey]];
380+
}
381+
}
382+
383+
// Add a newline to separate prefill email body and additions from what comes after.
384+
[prefilledEmailBodyWithEmailBodyAdditions appendString:@"\n"];
385+
386+
return prefilledEmailBodyWithEmailBodyAdditions;
387+
}
388+
371389
- (NSString *)_recentErrorLogMessagesAsPlainText:(NSArray *)logMessages count:(NSUInteger)errorLogsToInclude;
372390
{
373391
NSMutableString *recentErrorLogs = [NSMutableString new];

Logging/ARKLogDistributor.m

+28-5
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ - (instancetype)init;
7575
_logDistributingQueue.name = [NSString stringWithFormat:@"%@ Log Distributing Queue", self];
7676
_logDistributingQueue.maxConcurrentOperationCount = 1;
7777

78-
#ifdef __IPHONE_8_0
79-
if ([_logDistributingQueue respondsToSelector:@selector(setQualityOfService:)] /* iOS 8 or later */) {
80-
_logDistributingQueue.qualityOfService = NSQualityOfServiceBackground;
81-
}
82-
#endif
78+
[self _setDistributionQualityOfServiceBackground];
8379

8480
_logObservers = [NSMutableArray new];
8581

@@ -191,8 +187,10 @@ - (void)distributeAllPendingLogsWithCompletionHandler:(dispatch_block_t)completi
191187
{
192188
ARKCheckCondition(completionHandler != NULL, , @"Must provide a completion handler!");
193189

190+
[self _setDistributionQualityOfServiceUserInitiated];
194191
[self.logDistributingQueue addOperationWithBlock:^{
195192
[[NSOperationQueue mainQueue] addOperationWithBlock:completionHandler];
193+
[self _setDistributionQualityOfServiceBackground];
196194
}];
197195
}
198196

@@ -284,4 +282,29 @@ - (void)_logMessage_inLogDistributingQueue:(ARKLogMessage *)logMessage;
284282
}
285283
}
286284

285+
- (void)_setDistributionQualityOfServiceUserInitiated;
286+
{
287+
#ifdef __IPHONE_8_0
288+
[self _setDistributionQualityOfService:NSQualityOfServiceUserInitiated];
289+
#endif
290+
}
291+
292+
- (void)_setDistributionQualityOfServiceBackground;
293+
{
294+
#ifdef __IPHONE_8_0
295+
[self _setDistributionQualityOfService:NSQualityOfServiceBackground];
296+
#endif
297+
}
298+
299+
#ifdef __IPHONE_8_0
300+
301+
- (void)_setDistributionQualityOfService:(NSQualityOfService)qualityOfService;
302+
{
303+
if ([self.logDistributingQueue respondsToSelector:@selector(setQualityOfService:)] /* iOS 8 or later */) {
304+
self.logDistributingQueue.qualityOfService = qualityOfService;
305+
}
306+
}
307+
308+
#endif
309+
287310
@end

0 commit comments

Comments
 (0)