Authored by 孟顺

移除 crash 上报事件

review by days
... ... @@ -75,6 +75,7 @@
E7B8DE5E1A836F8700102CC4 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE5D1A836F8700102CC4 /* CoreTelephony.framework */; };
E7B8DE621A838EC200102CC4 /* AdSupport.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B8DE611A838EC200102CC4 /* AdSupport.framework */; };
E7E3A1871BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = E7E3A1861BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m */; };
F98D9182202304580054070B /* YHPatch.m in Sources */ = {isa = PBXBuildFile; fileRef = F98D9181202304580054070B /* YHPatch.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
... ... @@ -228,6 +229,8 @@
E7B8DE611A838EC200102CC4 /* AdSupport.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AdSupport.framework; path = System/Library/Frameworks/AdSupport.framework; sourceTree = SDKROOT; };
E7E3A1851BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "AFHTTPRequestOperationManager+YHPriorityRequest.h"; sourceTree = "<group>"; };
E7E3A1861BF098DA006A9266 /* AFHTTPRequestOperationManager+YHPriorityRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "AFHTTPRequestOperationManager+YHPriorityRequest.m"; sourceTree = "<group>"; };
F98D9181202304580054070B /* YHPatch.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YHPatch.m; sourceTree = "<group>"; };
F98D9183202304650054070B /* YHPatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YHPatch.h; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
... ... @@ -463,6 +466,8 @@
E7ADAE321AB946C100C9DD0B /* Model */ = {
isa = PBXGroup;
children = (
F98D9183202304650054070B /* YHPatch.h */,
F98D9181202304580054070B /* YHPatch.m */,
E7ADAE331AB946C100C9DD0B /* YHDevice.h */,
E7ADAE341AB946C100C9DD0B /* YHDevice.m */,
E7ADAE351AB946C100C9DD0B /* YHError.h */,
... ... @@ -693,6 +698,7 @@
E7A908731BB3C4B000E2EA39 /* YHPerformance.m in Sources */,
E7ADAE3B1AB946C100C9DD0B /* YHDevice.m in Sources */,
E79828121AA6A5120035137C /* YH_KeychainStore.m in Sources */,
F98D9182202304580054070B /* YHPatch.m in Sources */,
194EDC761A7F52D100421E6C /* main.m in Sources */,
E7ADAE5B1AB95BC800C9DD0B /* YHAssemblyAssistant.m in Sources */,
E7ADAE3C1AB946C100C9DD0B /* YHError.m in Sources */,
... ...
... ... @@ -6,7 +6,7 @@
//
//
#import <YH_Analytics/YH_Analytics.h>
#import "YH_Analytics.h"
@interface YHPatch : YHAnalyItemData
... ...
//
// YHCrashReporter.h
// YH_Analytics
//
// Created by 王钱钧 on 15/2/4.
// Copyright (c) 2015年 YOHO. All rights reserved.
// 负责crash信息收集
#import <Foundation/Foundation.h>
@interface YHCrashReporter : NSObject
+ (YHCrashReporter *)sharedInstance;
- (NSArray *)callstackAsArray;
- (void)handleSignal:(NSDictionary *)userInfo;
- (void)handleNSException:(NSDictionary *)userInfo;
@end
//
// YHCrashReporter.m
// YH_Analytics
//
// Created by 王钱钧 on 15/2/4.
// Copyright (c) 2015年 YOHO. All rights reserved.
//
#import "YHCrashReporter.h"
#import "YH_Analytics.h"
#import "YHError.h"
#include <signal.h>
#include <execinfo.h>
#pragma mark - C Fuctions
void sighandler(int signal)
{
const char* names[NSIG];
names[SIGABRT] = "SIGABRT";
names[SIGBUS] = "SIGBUS";
names[SIGFPE] = "SIGFPE";
names[SIGILL] = "SIGILL";
names[SIGPIPE] = "SIGPIPE";
names[SIGSEGV] = "SIGSEGV";
YHCrashReporter *crash = [YHCrashReporter sharedInstance];
NSArray *arr = [crash callstackAsArray];
NSDictionary *userInfo = @{
JsonKeyCrashCallstack : arr,
JsonKeyCrashSignal : @(signal),
JsonKeyCrashSignalName : [NSString stringWithUTF8String:names[signal]],
};
[crash performSelectorOnMainThread:@selector(handleSignal:) withObject:userInfo waitUntilDone:YES];
}
void uncaughtCrashExceptionHandler(NSException *exception)
{
YHCrashReporter *crash = [YHCrashReporter sharedInstance];
NSArray *arr = [exception callStackSymbols];
NSDictionary *userInfo = @{
JsonKeyCrashCallstack : arr,
JsonKeyCrashExceptionName : exception.name,
JsonKeyCrashExceptionReason : exception.reason,
};
[crash performSelectorOnMainThread:@selector(handleNSException:) withObject:userInfo waitUntilDone:YES];
}
@implementation YHCrashReporter
+ (YHCrashReporter *)sharedInstance
{
static YHCrashReporter *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[YHCrashReporter alloc] init];
});
return sharedInstance;
}
#pragma mark - Lifetime methods
- (id)init
{
self = [super init];
if (self) {
signal(SIGABRT, sighandler);
signal(SIGBUS, sighandler);
signal(SIGFPE, sighandler);
signal(SIGILL, sighandler);
signal(SIGPIPE, sighandler);
signal(SIGSEGV, sighandler);
NSSetUncaughtExceptionHandler(&uncaughtCrashExceptionHandler);
}
return self;
}
- (void)dealloc
{
signal(SIGABRT, SIG_DFL);
signal(SIGBUS, SIG_DFL);
signal(SIGFPE, SIG_DFL);
signal(SIGILL, SIG_DFL);
signal(SIGPIPE, SIG_DFL);
signal(SIGSEGV, SIG_DFL);
NSSetUncaughtExceptionHandler(NULL);
}
#pragma mark - methods
- (NSArray *)callstackAsArray
{
void *callstack[128];
const int numFrams = backtrace(callstack, 128);
char **symbols = backtrace_symbols(callstack, numFrams);
NSMutableArray *arr = [NSMutableArray arrayWithCapacity:numFrams];
for (int i = 0; i < numFrams; i++) {
[arr addObject:[NSString stringWithUTF8String:symbols[i]]];
}
free(symbols);
return arr;
}
- (void)handleSignal:(NSDictionary*)userInfo
{
YALog(@"crash============:\n%@", userInfo);
if (!userInfo || ![userInfo isKindOfClass:[NSDictionary class]]) {
return;
}
[[YH_Analytics sharedInstance] logError:kErrorTypeCrash parameters:@{ JsonKeyErrorST: userInfo}];
}
- (void)handleNSException:(NSDictionary*)userInfo
{
YALog(@"crash============:\n%@", userInfo);
if (!userInfo || ![userInfo isKindOfClass:[NSDictionary class]]) {
return;
}
[[YH_Analytics sharedInstance] logError:kErrorTypeCrash parameters:@{ JsonKeyErrorST: userInfo}];
}
@end
... ... @@ -13,7 +13,6 @@
#import "YHAnalyticsMacro.h"
#import "YH_Analytics.h"
#import "NSString+YHAnalytics.h"
#import "YHCrashReporter.h"
#import "YHAssemblyAssistant.h"
#import "OpenUDID.h"
#import "YHError.h"
... ... @@ -62,7 +61,6 @@
- (NSString *)timestamp;
- (void)registerCrashReporter;
- (void)registerAppWillEnterForegroundNotification;
- (void)resetSession;
- (void)uploadDiskData;
... ... @@ -142,13 +140,6 @@
#pragma mark - Private Method
- (void)registerCrashReporter
{
if (self.enableExceptionLog) {
[YHCrashReporter sharedInstance];
}
}
- (void)registerAppWillEnterForegroundNotification
{
// 当程序切换到后台,重置session 和 eventIndex
... ... @@ -213,8 +204,6 @@
[[YHAssemblyAssistant sharedInstance] prepareImmediUploadDic:appId sessionId:self.session channelId:self.channelId];
[self registerCrashReporter];
[self registerAppWillEnterForegroundNotification];
/*
... ...