diff --git a/Raven.podspec b/Raven.podspec index 5ed9f3a..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/getsentry/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 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 0761df9..5d73d6b 100644 --- a/Raven/RavenClient.m +++ b/Raven/RavenClient.m @@ -213,7 +213,7 @@ - (void)captureMessage:(NSString *)message } [[NSUserDefaults standardUserDefaults] synchronize]; } else { - [self sendDictionary:data]; + [self sendDictionary:data success:nil error:nil]; } } @@ -263,7 +263,7 @@ - (void)captureException:(NSException *)exception additionalExtra:(NSDictionary } [[NSUserDefaults standardUserDefaults] synchronize]; } else { - [self sendDictionary:data]; + [self sendDictionary:data success:nil error:nil]; } } @@ -312,24 +312,34 @@ - (void)captureException:(NSException *)exception method:(const char *)method fi } [[NSUserDefaults standardUserDefaults] synchronize]; } else { - [self sendDictionary:data]; + [self sendDictionary:data success:nil error:nil]; } } - (void)setupExceptionHandler { NSSetUncaughtExceptionHandler(&exceptionHandler); + [self flush]; +} + +- (void)flush +{ // 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:^{ + [reports removeObject:data]; + [[NSUserDefaults standardUserDefaults] setObject:reports 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]; } } + #pragma mark - Private methods - (NSString *)generateUUID { @@ -379,18 +389,18 @@ - (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{ if (!self.config) { NSLog(@"Sentry JSON (DSN not configured, will not be sent):\n%@\n", [[NSString alloc] initWithData:JSON encoding:NSUTF8StringEncoding]); return; } - + NSString *header = [NSString stringWithFormat:@"Sentry sentry_version=%@, sentry_client=%@, sentry_timestamp=%ld, sentry_key=%@, sentry_secret=%@", sentryProtocol, sentryClient, @@ -409,8 +419,16 @@ - (void)sendJSON:(NSData *)JSON { [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); + } } }]; } 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 diff --git a/RavenTests/RavenClientTest.m b/RavenTests/RavenClientTest.m index 6b53aba..b7fc511 100644 --- a/RavenTests/RavenClientTest.m +++ b/RavenTests/RavenClientTest.m @@ -12,7 +12,7 @@ @implementation MockRavenClient -- (void)sendDictionary:(NSDictionary *)dict +- (void)sendDictionary:(NSDictionary *)dict success:(void (^)(void))success error:(void (^)(NSError *))error; { self.lastEvent = dict; self.numEvents += 1;