ios開發中崩潰日誌log
typedef enum{
QFLogLevelFail = 0,
QFLogLevelError,
QFLogLevelWarning,
QFLogLevelInfo,
QFLogLevelDebug
}QFLogLevel;
void QFLogMessage(QFLogLevel level, BOOL waitUntilDone, NSString* message, …);
@interface QFLog : NSObject
{
QFLogLevel _level;
BOOL _isStarted;
NSThread *_thread;
NSString* _logDirectory;//日誌檔案目錄
NSFileHandle *_fileHandle;//日誌檔案控制代碼
NSString* _logName;//日誌檔名
NSArray *_theLevelStringArray;
NSDateFormatter *_dateFormatter;
}
@property (nonatomic, readwrite, assign) QFLogLevel level;
/**
* QFLog Singleton物件
*
* @return QFLog物件
*/
+ (QFLog *)sharedQFLog;
/**
* 開始記錄日誌
*/
- (void)startLogging;
/**
* 停止記錄日誌
*/
- (void)stopLogging;
- (BOOL)isFinished;
/**
* 刪除舊日誌
*/
- (void)removeOldLogs;
/**
* 上傳日誌
*/
- (void)uploadLogs;
@end
import “Dialog.h”
static UIWindow *g_alertWindow = nil;
@interface DialogViewController : UIViewController
{
UIView *_dialogView;
BOOL _modal;
}
@property(assign, readwrite, nonatomic) BOOL modal;
- (void)setDialogView:(UIView *)dialogView;
@end
@implementation DialogViewController
(void)dealloc
{
[_dialogView release];
_dialogView = nil;[super dealloc];
}(void)touchesBegan:(NSSet )touches withEvent:(UIEvent )event
{
if (_modal)
{
return;
}UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
if ( !CGRectContainsPoint(_dialogView.frame, touchPoint))
{
//關閉對話方塊
closeDialogView(QFCloseDialogViewAnimationNone, ^(BOOL finished) {});
}
}(void)viewDidLoad
{
[super viewDidLoad];
}
(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{CGFloat mainScreenWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat mainScreenHeight = [UIScreen mainScreen].bounds.size.height;if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft
||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
_dialogView.center = CGPointMake(mainScreenHeight/2.0, mainScreenWidth/2.0);
}
else
{
_dialogView.center = CGPointMake(mainScreenWidth/2.0, mainScreenHeight/2.0);
}
}(void)setDialogView:(UIView *)dialogView
{
[dialogView retain];
[_dialogView release];
_dialogView = dialogView;CGFloat mainScreenWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat mainScreenHeight = [UIScreen mainScreen].bounds.size.height;UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
if (orientation == UIDeviceOrientationLandscapeLeft
||
orientation == UIDeviceOrientationLandscapeRight)
{
_dialogView.center = CGPointMake(mainScreenHeight/2.0, mainScreenWidth/2.0);
}
else
{
_dialogView.center = CGPointMake(mainScreenWidth/2.0, mainScreenHeight/2.0);
}[self.view addSubview:dialogView];
}
@end
void showDialogView(UIView *view, BOOL modal, QFShowDialogViewAnimationOptions showDialogViewAnimationOption, void (^completion)(BOOL finished))
{
if (g_alertWindow == nil)
{
g_alertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
g_alertWindow.windowLevel = UIWindowLevelAlert;
g_alertWindow.backgroundColor = [UIColor clearColor];
[g_alertWindow makeKeyAndVisible];
}
DialogViewController *dialogViewController = [[[DialogViewController alloc] init] autorelease];
dialogViewController.modal = modal;
g_alertWindow.rootViewController = dialogViewController;
[dialogViewController setDialogView:view];
if (showDialogViewAnimationOption == QFShowDialogViewAnimationNone)
{
if (completion != nil)
{
completion(YES);
}
return;
}
else if (showDialogViewAnimationOption ==QFShowDialogViewAnimationFromLeft)
{
view.layer.transform = CATransform3DTranslate(view.layer.transform, -g_alertWindow.bounds.size.width, 0, 0);
}
else if (showDialogViewAnimationOption ==QFShowDialogViewAnimationFromTop)
{
view.layer.transform = CATransform3DTranslate(view.layer.transform, 0, -g_alertWindow.bounds.size.height, 0);
}
else if (showDialogViewAnimationOption ==QFShowDialogViewAnimationFromRight)
{
view.layer.transform = CATransform3DTranslate(view.layer.transform, g_alertWindow.bounds.size.width, 0, 0);
}
else if (showDialogViewAnimationOption ==QFShowDialogViewAnimationFromBottom)
{
view.layer.transform = CATransform3DTranslate(view.layer.transform, 0, g_alertWindow.bounds.size.height, 0);
}
else if (showDialogViewAnimationOption ==QFShowDialogViewAnimationFromCenter)
{
view.layer.transform = CATransform3DScale(view.layer.transform, 0.001, 0.001, 1);
}
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
view.layer.transform = CATransform3DIdentity;
} completion:^(BOOL finished) {
if (completion != nil)
{
completion(YES);
}
}];
}
void closeDialogView(QFCloseDialogViewViewAnimationOptions closeDialogViewViewAnimationOption, void (^completion)(BOOL finished))
{
CATransform3D transform;
if (closeDialogViewViewAnimationOption == QFCloseDialogViewAnimationNone)
{
if (g_alertWindow != nil)
{
[g_alertWindow release];
g_alertWindow = nil;
}
if (completion != nil)
{
completion(YES);
}
return;
}
else if (closeDialogViewViewAnimationOption == QFCloseDialogViewAnimationToLeft)
{
transform = CATransform3DTranslate(g_alertWindow.rootViewController.view.layer.transform, -g_alertWindow.frame.size.width, 0, 0);
}
else if (closeDialogViewViewAnimationOption == QFCloseDialogViewAnimationToTop)
{
transform = CATransform3DTranslate(g_alertWindow.rootViewController.view.layer.transform, 0, -g_alertWindow.frame.size.height, 0);
}
else if (closeDialogViewViewAnimationOption == QFCloseDialogViewAnimationToRight)
{
transform = CATransform3DTranslate(g_alertWindow.rootViewController.view.layer.transform, g_alertWindow.frame.size.width, 0, 0);
}
else if (closeDialogViewViewAnimationOption == QFCloseDialogViewAnimationToBottom)
{
transform = CATransform3DTranslate(g_alertWindow.rootViewController.view.layer.transform, 0,g_alertWindow.frame.size.height, 0);
}
else if (closeDialogViewViewAnimationOption == QFCloseDialogViewAnimationToCenter)
{
transform = CATransform3DScale(g_alertWindow.rootViewController.view.layer.transform, 0.001, 0.001, 1);
}
[UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
g_alertWindow.rootViewController.view.layer.transform = transform;
} completion:^(BOOL finished) {
if (g_alertWindow != nil)
{
[g_alertWindow release];
g_alertWindow = nil;
}
if (completion != nil)
{
completion(YES);
}
}];
}