From f963e8706e03d290863d92ca443c12d0442e16a3 Mon Sep 17 00:00:00 2001 From: sblepa Date: Wed, 19 Nov 2014 13:41:01 +0200 Subject: [PATCH 1/5] Added support for keeping reports if no network available --- Raven.xcodeproj/project.pbxproj | 3 ++- Raven/RavenClient.m | 23 +++++++++++++---------- Raven/RavenClient_Private.h | 4 ++-- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Raven.xcodeproj/project.pbxproj b/Raven.xcodeproj/project.pbxproj index bad1a4f..d182505 100644 --- a/Raven.xcodeproj/project.pbxproj +++ b/Raven.xcodeproj/project.pbxproj @@ -213,7 +213,7 @@ name = RavenTests; productName = RavenTests; productReference = 0A46FEBA156FA72300D97F26 /* RavenTests.octest */; - productType = "com.apple.product-type.bundle"; + productType = "com.apple.product-type.bundle.ocunit-test"; }; /* End PBXNativeTarget section */ @@ -221,6 +221,7 @@ 0A46FE90156FA72300D97F26 /* Project object */ = { isa = PBXProject; attributes = { + LastTestingUpgradeCheck = 0610; LastUpgradeCheck = 0460; ORGANIZATIONNAME = Gangverk; }; diff --git a/Raven/RavenClient.m b/Raven/RavenClient.m index 0123c7d..8c7f617 100644 --- a/Raven/RavenClient.m +++ b/Raven/RavenClient.m @@ -209,7 +209,7 @@ - (void)captureMessage:(NSString *)message } [[NSUserDefaults standardUserDefaults] synchronize]; } else { - [self sendDictionary:data]; + [self sendDictionary:data success:nil error:nil]; } } @@ -259,7 +259,7 @@ - (void)captureException:(NSException *)exception additionalExtra:(NSDictionary } [[NSUserDefaults standardUserDefaults] synchronize]; } else { - [self sendDictionary:data]; + [self sendDictionary:data success:nil error:nil]; } } @@ -308,7 +308,7 @@ - (void)captureException:(NSException *)exception method:(const char *)method fi } [[NSUserDefaults standardUserDefaults] synchronize]; } else { - [self sendDictionary:data]; + [self sendDictionary:data success:nil error:nil]; } } @@ -316,13 +316,16 @@ - (void)setupExceptionHandler { NSSetUncaughtExceptionHandler(&exceptionHandler); // Process saved crash reports - NSArray *reports = [[NSUserDefaults standardUserDefaults] objectForKey:userDefaultsKey]; + NSMutableArray *reports = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:userDefaultsKey]]; if (reports != nil && [reports count]) { for (NSDictionary *data in reports) { - [self sendDictionary:data]; + [self sendDictionary:data success:^{ + [[NSUserDefaults standardUserDefaults] setObject:[NSArray array] forKey:userDefaultsKey]; + [[NSUserDefaults standardUserDefaults] synchronize]; + } error:^(NSError *err) { + // Coudn't send report, keep for next time + }]; } - [[NSUserDefaults standardUserDefaults] setObject:[NSArray array] forKey:userDefaultsKey]; - [[NSUserDefaults standardUserDefaults] synchronize]; } } @@ -375,12 +378,12 @@ - (NSDictionary *)prepareDictionaryForMessage:(NSString *)message nil]; } -- (void)sendDictionary:(NSDictionary *)dict { +- (void)sendDictionary:(NSDictionary *)dict success:(void (^)(void))success error:(void (^)(NSError * err))error{ NSData *JSON = [self encodeJSON:dict]; - [self sendJSON:JSON]; + [self sendJSON:JSON success:success error:error]; } -- (void)sendJSON:(NSData *)JSON { +- (void)sendJSON:(NSData *)JSON success:(void (^)(void))success error:(void (^)(NSError *))error{ NSString *header = [NSString stringWithFormat:@"Sentry sentry_version=%@, sentry_client=%@, sentry_timestamp=%ld, sentry_key=%@, sentry_secret=%@", sentryProtocol, sentryClient, diff --git a/Raven/RavenClient_Private.h b/Raven/RavenClient_Private.h index b688c17..1f72767 100644 --- a/Raven/RavenClient_Private.h +++ b/Raven/RavenClient_Private.h @@ -23,7 +23,7 @@ culprit:(NSString *)culprit stacktrace:(NSArray *)stacktrace exception:(NSDictionary *)exceptionDict; -- (void)sendDictionary:(NSDictionary *)dict; -- (void)sendJSON:(NSData *)JSON; +- (void)sendDictionary:(NSDictionary *)dict success:(void (^)(void))success error:(void (^)(NSError *))error; +- (void)sendJSON:(NSData *)JSON success:(void (^)(void))success error:(void (^)(NSError *err))error; @end From 3865353364316e429a3e82793ab855550c6aa3af Mon Sep 17 00:00:00 2001 From: sblepa Date: Wed, 19 Nov 2014 13:43:50 +0200 Subject: [PATCH 2/5] Updated podspec --- Raven.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Raven.podspec b/Raven.podspec index 1eb1498..a879fc2 100644 --- a/Raven.podspec +++ b/Raven.podspec @@ -5,7 +5,7 @@ Pod::Spec.new do |s| s.homepage = "https://getsentry.com/" s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "David Cramer" => "dcramer@gmail.com" } - s.source = { :git => "https://github.com/getsentry/raven-objc.git", :tag => s.version.to_s } + s.source = { :git => "https://github.com/sblepa/raven-objc.git", :tag => s.version.to_s } s.source_files = ['Raven'] s.requires_arc = true end From 714209eafbbc67b582aa5526b085abd0d0fb3de1 Mon Sep 17 00:00:00 2001 From: sblepa Date: Wed, 19 Nov 2014 14:41:01 +0200 Subject: [PATCH 3/5] Fix --- Raven/RavenClient.m | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Raven/RavenClient.m b/Raven/RavenClient.m index 8c7f617..1fb401c 100644 --- a/Raven/RavenClient.m +++ b/Raven/RavenClient.m @@ -320,7 +320,8 @@ - (void)setupExceptionHandler { if (reports != nil && [reports count]) { for (NSDictionary *data in reports) { [self sendDictionary:data success:^{ - [[NSUserDefaults standardUserDefaults] setObject:[NSArray array] forKey:userDefaultsKey]; + [reports removeObject:data]; + [[NSUserDefaults standardUserDefaults] setObject:reports forKey:userDefaultsKey]; [[NSUserDefaults standardUserDefaults] synchronize]; } error:^(NSError *err) { // Coudn't send report, keep for next time @@ -402,8 +403,16 @@ - (void)sendJSON:(NSData *)JSON success:(void (^)(void))success error:(void (^)( [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { if (data) { NSLog(@"JSON sent to Sentry"); + if (success != nil) + { + success(); + } } else { NSLog(@"Connection failed! Error - %@ %@", [connectionError localizedDescription], [[connectionError userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); + if (error != nil) + { + error(connectionError); + } } }]; } From 7dc22fd108520a2e8ac53fd84fd0726b79e3f231 Mon Sep 17 00:00:00 2001 From: Ash Thwaites Date: Tue, 24 Mar 2015 15:36:19 +0200 Subject: [PATCH 4/5] update pod spec --- Raven.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Raven.podspec b/Raven.podspec index 7949a87..9136327 100644 --- a/Raven.podspec +++ b/Raven.podspec @@ -5,7 +5,7 @@ Pod::Spec.new do |s| s.homepage = "https://getsentry.com/" s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { "David Cramer" => "dcramer@gmail.com" } - s.source = { :git => "https://github.com/sblepa/raven-objc.git", :tag => s.version.to_s } + s.source = { :git => "https://github.com/toolboxash/raven-objc.git", :tag => s.version.to_s } s.source_files = ['Raven'] s.requires_arc = true end From a36c8997f24142ab221b986e7ea7a5e037871fd7 Mon Sep 17 00:00:00 2001 From: Ash Thwaites Date: Wed, 25 Mar 2015 17:04:32 +0200 Subject: [PATCH 5/5] Support flushing of cached events without having to add an exception handler --- Raven/RavenClient.h | 1 + Raven/RavenClient.m | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Raven/RavenClient.h b/Raven/RavenClient.h index 3905157..33e8e9b 100644 --- a/Raven/RavenClient.h +++ b/Raven/RavenClient.h @@ -114,5 +114,6 @@ typedef enum { - (void)captureException:(NSException *)exception additionalExtra:(NSDictionary *)additionalExtra additionalTags:(NSDictionary *)additionalTags sendNow:(BOOL)sendNow; - (void)captureException:(NSException*)exception method:(const char*)method file:(const char*)file line:(NSInteger)line sendNow:(BOOL)sendNow; - (void)setupExceptionHandler; +- (void)flush; @end diff --git a/Raven/RavenClient.m b/Raven/RavenClient.m index 02cfb21..5d73d6b 100644 --- a/Raven/RavenClient.m +++ b/Raven/RavenClient.m @@ -318,7 +318,12 @@ - (void)captureException:(NSException *)exception method:(const char *)method fi - (void)setupExceptionHandler { NSSetUncaughtExceptionHandler(&exceptionHandler); + [self flush]; +} + +- (void)flush +{ // Process saved crash reports NSMutableArray *reports = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:userDefaultsKey]]; if (reports != nil && [reports count]) { @@ -334,6 +339,7 @@ - (void)setupExceptionHandler { } } + #pragma mark - Private methods - (NSString *)generateUUID {