Skip to content

Commit

Permalink
Crash client delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
kaler committed Aug 4, 2010
1 parent 33d79ec commit cf9a8fc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Classes/CrashController.h
Expand Up @@ -10,9 +10,14 @@

@class CrashLogger;

@protocol CrashSaveDelegate
- (void)onCrash;
@end

@interface CrashController : NSObject
{
CrashLogger *logger;
id <CrashSaveDelegate> delegate;
}

+ (CrashController*)sharedInstance;
Expand All @@ -22,4 +27,6 @@
- (void)handleSignal:(NSDictionary*)userInfo;
- (void)handleNSException:(NSDictionary*)userInfo;

@property (nonatomic, assign) id <CrashSaveDelegate> delegate;

@end
8 changes: 7 additions & 1 deletion Classes/CrashController.m
Expand Up @@ -49,7 +49,7 @@ @interface CrashController()
@end

@implementation CrashController
@synthesize logger;
@synthesize logger, delegate;

#pragma mark Singleton methods

Expand Down Expand Up @@ -161,11 +161,17 @@ - (NSArray*)callstackAsArray

- (void)handleSignal:(NSDictionary*)userInfo
{
if (self.delegate)
[self.delegate onCrash];

[self.logger sendCrash:userInfo];
}

- (void)handleNSException:(NSDictionary*)userInfo
{
if (self.delegate)
[self.delegate onCrash];

[self.logger sendCrash:userInfo];
}

Expand Down
3 changes: 2 additions & 1 deletion Classes/CrashKitAppDelegate.h
Expand Up @@ -7,8 +7,9 @@
//

#import <UIKit/UIKit.h>
#import "CrashController.h"

@interface CrashKitAppDelegate : NSObject <UIApplicationDelegate>
@interface CrashKitAppDelegate : NSObject <UIApplicationDelegate, CrashSaveDelegate>
{
UIWindow *window;
UIViewController *rootViewController;
Expand Down
18 changes: 16 additions & 2 deletions Classes/CrashKitAppDelegate.m
Expand Up @@ -21,8 +21,11 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
{
[window makeKeyAndVisible];

[[CrashController sharedInstance] sendCrashReportsToEmail:@"crash@smartfulstudios.com"
withViewController:rootViewController];
CrashController *crash = [CrashController sharedInstance];
[crash sendCrashReportsToEmail:@"crash@smartfulstudios.com"
withViewController:rootViewController];
crash.delegate = self;


[self performSelector:@selector(sigabrt) withObject:nil afterDelay:0.1];
// [self performSelector:@selector(sigbus) withObject:nil afterDelay:0.1];
Expand All @@ -35,6 +38,17 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

- (void)onCrash
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Crash"
message:@"The App has crashed and will attempt to send a crash report"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}

#pragma mark -
#pragma mark Memory management

Expand Down

0 comments on commit cf9a8fc

Please sign in to comment.