Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'release/2.1.7'
  • Loading branch information
ashtom committed Mar 25, 2012
2 parents cc17bc2 + df09c06 commit d392497
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 34 deletions.
5 changes: 0 additions & 5 deletions client/iOS/BWQuincyManager.h
Expand Up @@ -153,7 +153,6 @@ typedef enum CrashReportStatus {
BOOL _showAlwaysButton;
BOOL _feedbackActivated;
BOOL _autoSubmitCrashReport;
BOOL _autoSubmitDeviceUDID;

BOOL _didCrashInLastSession;

Expand Down Expand Up @@ -215,10 +214,6 @@ typedef enum CrashReportStatus {
// if NO, the user will be asked if the crash report can be submitted (default)
@property (nonatomic, assign, getter=isAutoSubmitCrashReport) BOOL autoSubmitCrashReport;

// if YES, the device UDID will be submitted as the user id, without the need to define it in the crashReportUserID delegate (meant for beta versions!)
// if NO, the crashReportUserID delegate defines what to be sent as user id (default)
@property (nonatomic, assign, getter=isAutoSubmitDeviceUDID) BOOL autoSubmitDeviceUDID;

// will return if the last session crashed, to e.g. make sure a "rate my app" alert will not show up
@property (nonatomic, readonly) BOOL didCrashInLastSession;

Expand Down
46 changes: 17 additions & 29 deletions client/iOS/BWQuincyManager.m
Expand Up @@ -36,7 +36,7 @@
#include <inttypes.h> //needed for PRIx64 macro

#define SDK_NAME @"Quincy"
#define SDK_VERSION @"2.1.6"
#define SDK_VERSION @"2.1.7"

NSBundle *quincyBundle(void) {
static NSBundle* bundle = nil;
Expand Down Expand Up @@ -78,6 +78,8 @@ - (NSString *)_getDevicePlatform;
- (BOOL)hasNonApprovedCrashReports;
- (BOOL)hasPendingCrashReport;

@property (nonatomic, retain) NSFileManager *fileManager;

@end

@implementation BWQuincyManager
Expand All @@ -87,13 +89,14 @@ @implementation BWQuincyManager
@synthesize showAlwaysButton = _showAlwaysButton;
@synthesize feedbackActivated = _feedbackActivated;
@synthesize autoSubmitCrashReport = _autoSubmitCrashReport;
@synthesize autoSubmitDeviceUDID = _autoSubmitDeviceUDID;
@synthesize languageStyle = _languageStyle;
@synthesize didCrashInLastSession = _didCrashInLastSession;
@synthesize loggingEnabled = _loggingEnabled;

@synthesize appIdentifier = _appIdentifier;

@synthesize fileManager = _fileManager;

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
+(BWQuincyManager *)sharedQuincyManager {
static BWQuincyManager *sharedInstance = nil;
Expand Down Expand Up @@ -131,12 +134,12 @@ - (id) init {
_languageStyle = nil;
_didCrashInLastSession = NO;
_loggingEnabled = NO;
_fileManager = [[NSFileManager alloc] init];

self.delegate = nil;
self.feedbackActivated = NO;
self.showAlwaysButton = NO;
self.autoSubmitCrashReport = NO;
self.autoSubmitDeviceUDID = NO;

NSString *testValue = [[NSUserDefaults standardUserDefaults] stringForKey:kQuincyKitAnalyzerStarted];
if (testValue) {
Expand All @@ -159,13 +162,11 @@ - (id) init {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
_crashesDir = [[NSString stringWithFormat:@"%@", [[paths objectAtIndex:0] stringByAppendingPathComponent:@"/crashes/"]] retain];

NSFileManager *fm = [NSFileManager defaultManager];

if (![fm fileExistsAtPath:_crashesDir]) {
if (![self.fileManager fileExistsAtPath:_crashesDir]) {
NSDictionary *attributes = [NSDictionary dictionaryWithObject: [NSNumber numberWithUnsignedLong: 0755] forKey: NSFilePosixPermissions];
NSError *theError = NULL;

[fm createDirectoryAtPath:_crashesDir withIntermediateDirectories: YES attributes: attributes error: &theError];
[self.fileManager createDirectoryAtPath:_crashesDir withIntermediateDirectories: YES attributes: attributes error: &theError];
}

PLCrashReporter *crashReporter = [PLCrashReporter sharedReporter];
Expand Down Expand Up @@ -213,6 +214,9 @@ - (void) dealloc {
[_crashesDir release];
[_crashFiles release];

[_fileManager release];
_fileManager = nil;

[super dealloc];
}

Expand Down Expand Up @@ -305,16 +309,14 @@ - (BOOL)hasNonApprovedCrashReports {

- (BOOL)hasPendingCrashReport {
if (_crashReportActivated) {
NSFileManager *fm = [NSFileManager defaultManager];

if ([_crashFiles count] == 0 && [fm fileExistsAtPath:_crashesDir]) {
if ([_crashFiles count] == 0 && [self.fileManager fileExistsAtPath:_crashesDir]) {
NSString *file = nil;
NSError *error = NULL;

NSDirectoryEnumerator *dirEnum = [fm enumeratorAtPath: _crashesDir];
NSDirectoryEnumerator *dirEnum = [self.fileManager enumeratorAtPath: _crashesDir];

while ((file = [dirEnum nextObject])) {
NSDictionary *fileAttributes = [fm attributesOfItemAtPath:[_crashesDir stringByAppendingPathComponent:file] error:&error];
NSDictionary *fileAttributes = [self.fileManager attributesOfItemAtPath:[_crashesDir stringByAppendingPathComponent:file] error:&error];
if ([[fileAttributes objectForKey:NSFileSize] intValue] > 0) {
[_crashFiles addObject:file];
}
Expand Down Expand Up @@ -462,28 +464,16 @@ - (NSString *)_getDevicePlatform {
return platform;
}

- (NSString *)deviceIdentifier {
if ([[UIDevice currentDevice] respondsToSelector:@selector(uniqueIdentifier)]) {
return [[UIDevice currentDevice] performSelector:@selector(uniqueIdentifier)];
}
else {
return @"invalid";
}
}

- (void)_performSendingCrashReports {
NSMutableDictionary *approvedCrashReports = [NSMutableDictionary dictionaryWithDictionary:[[NSUserDefaults standardUserDefaults] dictionaryForKey: kApprovedCrashReports]];

NSFileManager *fm = [NSFileManager defaultManager];
NSError *error = NULL;

NSString *userid = @"";
NSString *contact = @"";
NSString *description = @"";

if (self.autoSubmitDeviceUDID && [[NSBundle mainBundle] pathForResource:@"embedded" ofType:@"mobileprovision"]) {
userid = [self deviceIdentifier];
} else if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashReportUserID)]) {
if (self.delegate != nil && [self.delegate respondsToSelector:@selector(crashReportUserID)]) {
userid = [self.delegate crashReportUserID] ?: @"";
}

Expand Down Expand Up @@ -537,7 +527,7 @@ - (void)_performSendingCrashReports {
[approvedCrashReports setObject:[NSNumber numberWithBool:YES] forKey:[_crashFiles objectAtIndex:i]];
} else {
// we cannot do anything with this report, so delete it
[fm removeItemAtPath:filename error:&error];
[self.fileManager removeItemAtPath:filename error:&error];
}
}

Expand All @@ -555,10 +545,8 @@ - (void)_performSendingCrashReports {
- (void)_cleanCrashReports {
NSError *error = NULL;

NSFileManager *fm = [NSFileManager defaultManager];

for (NSUInteger i=0; i < [_crashFiles count]; i++) {
[fm removeItemAtPath:[_crashesDir stringByAppendingPathComponent:[_crashFiles objectAtIndex:i]] error:&error];
[self.fileManager removeItemAtPath:[_crashesDir stringByAppendingPathComponent:[_crashFiles objectAtIndex:i]] error:&error];
}
[_crashFiles removeAllObjects];

Expand Down

0 comments on commit d392497

Please sign in to comment.