Invalid pointer dequeuedpop from empty listfree list 内存错误怎么解决

My app runs perfectly on simulator.
But when I run it on device to test, the app crashed.
The displayed error :
"malloc: * error for object 0x: Invalid pointer dequeued from free list * set a breakpoint in malloc_error_break to debug";
And another error sometimes happens :
"Thread 6 com.apple.NSURLConnectionLoader: Program received signal: EXC_BAD_ACCESS"
This two errors are random, it happens after the app runs two or three minutes.
I searched Google and find some solution.
It says that set a breakpoint in malloc_error_break to debug, but this only work on simulator. Even I set the malloc_error_break, the app still crush and it does not display anything, I only can see that error message.
This is big project, I really do not know which part of the code cause the problem and which part of the code I need to post.
But I have doubt with one of the class, my 'SynchroningView'.
This view will be displayed if only my app make synchronisation with the server. It means this view is included in almost all the Viewcontroller in my project.
Here is my 'SynchroningView' class:
"SynchroningView.h"
#import &UIKit/UIKit.h&
@class SynchroningV
@protocol SynchroningViewDelegate
- (void)SynchroningViewCancelButtonDidClicked:(SynchroningView *)synchroningV
- (void)SynchroningViewStartTherapyButtonDidClicked:(SynchroningView *)synchroningV
@interface SynchroningView : UIView &DataManagerDelegate&
@property (nonatomic, assign) id&SynchroningViewDelegate&delegateC
@property (nonatomic, retain) UIButton *containerB
@property (nonatomic, retain) Patient *singleP
- (instancetype)initWithFrame:(CGRect)
- (void)showInView:(UIView *)
- (void)dismissMenuP
SynchroningView.m
#import "SDDemoItemView.h"
#import "SDPieLoopProgressView.h"
#define Directory_Document
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define FileName_Image_SynchroningView_BackGroundImageName @"SynchroningView_BackGroundImage"
#define FilePath_Image_SynchroningView_BackGroundImageName [Directory_Document stringByAppendingPathComponent:FileName_Image_SynchroningView_BackGroundImageName]
@interface SynchroningView ()
(nonatomic, strong) DataManager*
(nonatomic, retain) UILabel*
(nonatomic, retain) UIButton*
(nonatomic, retain) CoolButton* ConfirmB
(nonatomic, retain) CoolButton* startTherapyB
(nonatomic, strong) SDDemoItemView* demoProgressV
@interface SynchroningView ()
@implementation SynchroningView
-(void)dealloc
//get the background Image, make it blur and save it. In this way I do not have to use Blur function everytim, I use the blured image directly
- (UIImage *)getBackGroundImage
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:FilePath_Image_SynchroningView_BackGroundImageName]) {
return [UIImage imageWithContentsOfFile:FilePath_Image_SynchroningView_BackGroundImageName];
UIImage *backImage = [UIImage imageWithContentsOfFile:kBackgroundImagePath];
backImage = [backImage blurWithFloat:20.0f];
NSData * binaryImageData = UIImagePNGRepresentation(backImage);
if ([binaryImageData writeToFile:FilePath_Image_SynchroningView_BackGroundImageName atomically:YES]) {
return backI
return [UIImage imageWithContentsOfFile:kBackgroundImagePath];
-(instancetype)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self) {
_blinking = NO;
self.dataManager = [[DataManager alloc] init];
self.dataManager.DelegateCustom =
self.backgroundColor = [UIColor clearColor];
self.containerButton = [[UIButton alloc] init];
[self.containerButton setBackgroundColor:RGBA_Custom(0, 0, 0, 0.6f)];
[self.containerButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin];
UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[self addSubview:shadowView];
shadowView.backgroundColor = RGBA_Custom(230, 249, 251, 0.96f);
shadowView.layer.borderWidth = 2*IPAD;
shadowView.layer.borderColor = [RGBA_Custom(199, 199, 199, 1.0f) CGColor];
shadowView.layer.shadowColor = [UIColor blackColor].CGC
shadowView.layer.shadowOpacity = 0.4;
shadowView.layer.shadowRadius = 4*IPAD;
shadowView.layer.shadowOffset = CGSizeMake(4.0f*IPAD, 4.0f*IPAD);
shadowView.layer.cornerRadius = 6*IPAD;
shadowView.userInteractionEnabled = NO;
UIImageView *backGround = [[UIImageView alloc] initWithImage:[self getBackGroundImage]];
backGround.frame = CGRectMake(0, 0, shadowView.frame.size.width, shadowView.frame.size.height);
backGround.backgroundColor = [UIColor clearColor];
[shadowView addSubview:backGround];
backGround.layer.cornerRadius = shadowView.layer.cornerR
backGround.layer.masksToBounds = YES;
ImageWIDTH_ = self.frame.size.height*0.3;
self.demoProgressView =[SDDemoItemView demoItemViewWithClass:[SDPieLoopProgressView class]];
self.demoProgressView.frame = CGRectMake((self.frame.size.width - ImageWIDTH_)/2,
kFromLeft,
ImageWIDTH_,
ImageWIDTH_);
[self addSubview:self.demoProgressView];
self.messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(kFromLeft,
self.demoProgressView.frame.origin.y + self.demoProgressView.frame.size.height + kFromLeft,
self.frame.size.width - kFromLeft*2,
self.frame.size.height - (self.demoProgressView.frame.origin.y + self.demoProgressView.frame.size.height + kFromLeft*2))];
self.messageLabel.backgroundColor = [UIColor clearColor];
self.messageLabel.textColor = [UIColor blackColor];
self.messageLabel.textAlignment = NSTextAlignmentC
self.messageLabel.numberOfLines = 0;
self.messageLabel.lineBreakMode = NSLineBreakByWordW
self.messageLabel.font = [UIFont boldSystemFontOfSize:kIPAD ? 20:12];
self.messageLabel.text = @"";
self.messageLabel.adjustsFontSizeToFitWidth = YES;
[self addSubview:self.messageLabel];
CGFloat BtnHeight = kIPAD ? 40
self.CancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.CancelButton.frame = CGRectMake(self.frame.size.width - kFromLeft*0.5 - BtnHeight,
kFromLeft*0.5,
BtnHeight,
BtnHeight);
self.CancelButton.backgroundColor = [UIColor clearColor];
[self.CancelButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"utilities_close" ofType:@"png"]] forState:UIControlStateNormal];
[self.CancelButton addTarget:self action:@selector(pressCancelButton:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.CancelButton];
BtnHeight = kIPAD ? 70
CGFloat BtnWidth
= self.frame.size.width/4;
ConfirmButtonStr = NSLocalizedString(@"Confirm", nil);
ExpectedSize = [ConfirmButtonStr sizeWithFont:self.messageLabel.font constrainedToSize:CGSizeMake(VIEW_WIDTH, BtnHeight) lineBreakMode:NSLineBreakByWordWrapping];
ExpectedSize = CGSizeMake(ExpectedSize.width + 30*IPAD, ExpectedSize.height);
self.ConfirmButton = [CoolButton buttonWithType:UIButtonTypeCustom];
self.ConfirmButton.frame = CGRectMake((self.frame.size.width - ExpectedSize.width)/2,
self.frame.size.height - BtnHeight - kFromLeft,
ExpectedSize.width,
BtnHeight);
self.ConfirmButton.titleLabel.font = self.messageLabel.
[self.ConfirmButton setTitle:ConfirmButtonStr forState:UIControlStateNormal];
[self.ConfirmButton addTarget:self action:@selector(pressConfirmButton:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.ConfirmButton];
BtnWidth = self.frame.size.width*0.6;
startTherapyButtonStr = NSLocalizedString(@"StartTerapia", nil);
ExpectedSize = [startTherapyButtonStr sizeWithFont:self.messageLabel.font constrainedToSize:CGSizeMake(VIEW_WIDTH, BtnHeight) lineBreakMode:NSLineBreakByWordWrapping];
ExpectedSize = CGSizeMake(ExpectedSize.width + 30*IPAD, ExpectedSize.height);
self.startTherapyButton = [CoolButton buttonWithType:UIButtonTypeCustom];
self.startTherapyButton.frame = CGRectMake((self.frame.size.width - ExpectedSize.width)/2,
self.ConfirmButton.frame.origin.y,
ExpectedSize.width,
self.ConfirmButton.frame.size.height);
self.startTherapyButton.titleLabel.font = self.messageLabel.
[self.startTherapyButton setTitle:startTherapyButtonStr forState:UIControlStateNormal];
[self.startTherapyButton addTarget:self action:@selector(startTherapyButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.startTherapyButton];
self.CancelButton.alpha
self.ConfirmButton.alpha
self.startTherapyButton.alpha
if (self.dataManager.firstSynchronizationAgain == 1 && [AccessedInfo getAccessedInfo]) {
UILabel *alertInfoLabel = [[UILabel alloc] initWithFrame:CGRectMake(kFromLeft,
self.frame.size.width - kFromLeft*2,
VIEW_HEIGHT)];
alertInfoLabel.backgroundColor = [UIColor clearColor];
alertInfoLabel.textColor = COLOR_CIRCLE;
alertInfoLabel.textAlignment = NSTextAlignmentC
alertInfoLabel.numberOfLines = 0;
alertInfoLabel.lineBreakMode = NSLineBreakByWordW
alertInfoLabel.font = [UIFont systemFontOfSize:self.startTherapyButton.titleLabel.font.pointSize-2];
alertInfoLabel.text = NSLocalizedString(@"SynchronizingNew", nil);
ExpectedSize = [alertInfoLabel.text sizeWithFont:alertInfoLabel.font constrainedToSize:alertInfoLabel.frame.size lineBreakMode:NSLineBreakByWordWrapping];
alertInfoLabel.frame = CGRectMake(alertInfoLabel.frame.origin.x,
self.startTherapyButton.frame.origin.y - ExpectedSize.height - IPAD*2,
alertInfoLabel.frame.size.width,
ExpectedSize.height);
[self addSubview:alertInfoLabel];
[self.containerButton addSubview:self];
//show the synchronization result message
- (void)setMessageLabelString:(NSString *)labelName
self.messageLabel.text = labelN
ExpectedSize = [labelName sizeWithFont:self.messageLabel.font constrainedToSize:CGSizeMake(self.messageLabel.frame.size.width, VIEW_HEIGHT) lineBreakMode:NSLineBreakByWordWrapping];
self.messageLabel.frame = CGRectMake(self.messageLabel.frame.origin.x,
self.messageLabel.frame.origin.y,
self.messageLabel.frame.size.width,
ExpectedSize.height);
timer = [NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:@selector(MessageLabelBlinking) userInfo:nil repeats:YES];
self.messageLabel.adjustsFontSizeToFitWidth = YES;
- (void)MessageLabelBlinking
if (_blinking) {
NSString *threeDot = @".....";
if ([self.messageLabel.text rangeOfString:threeDot].location == NSNotFound) {
self.messageLabel.text = [self.messageLabel.text stringByAppendingString:@"."];
self.messageLabel.text = [self.messageLabel.text stringByReplacingOccurrencesOfString:threeDot withString:@""];
[timer invalidate];
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
//init the data processing block
- (void)initCustomOtherParameters
self.dataManager.DelegateCustom =
self.dataManager.blockProcessingData = ^(float allCommand, float restCommand){
if (allCommand == 0) {
[[SingletonOperationQueue mainQueue] addOperationWithBlock:^{
self.demoProgressView.progressView.progress = 1;
NSString *messageStr = [NSLocalizedString(@"SuccessfulSynchronized", nil) stringByAppendingFormat:@"\n%@", NSLocalizedString(@"EmptyTherapy", nil)];
[self setMessageLabelString:messageStr];
_blinking = NO;
self.CancelButton.alpha
float percenAger = (restCommand/allCommand);
percenAger = 1 - percenA
[[SingletonOperationQueue mainQueue] addOperationWithBlock:^{
self.demoProgressView.progressView.progress = percenA
if (restCommand == 0) {
[self downloadZipFile];
[Patient RemovePatient];
[self.singlePatient SavePatient];
- (void)showInView:(UIView *)view
self.transform = CGAffineTransformScale(self.transform, 0.8, 0.8);
self.containerButton.alpha = 0.0f;
self.containerButton.frame = view.
[view addSubview:self.containerButton];
[UIView animateWithDuration:0.15 animations:^{
self.containerButton.alpha = 1.0f;
self.transform = CGAffineTransformScale(self.transform, 1.4, 1.4);
}completion:^(BOOL finished) {
if (finished) {
[UIView animateWithDuration:0.20 animations:^{
self.transform = CGAffineTransformI
[self sendConnectionTestRequest];
self.transform = CGAffineTransformI
[self sendConnectionTestRequest];
- (void)dismissMenuPopover
[self hide];
- (void)hide
[UIView animateWithDuration:0.25 animations:^{
self.transform = CGAffineTransformScale(self.transform, 0.8, 0.8);
self.containerButton.alpha = 0.0f;
}completion:^(BOOL finished) {
if (finished) {
[self.containerButton removeFromSuperview];
- (void)pressCancelButton:(UIButton *)button
[self.dataManager CommunicationCancel];
[self.delegateCustom SynchroningViewCancelButtonDidClicked:self];
- (void)startTherapyButtonDidClicked:(UIButton *)button
[self.delegateCustom SynchroningViewStartTherapyButtonDidClicked:self];
- (void)pressConfirmButton:(UIButton *)button
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha
self.ConfirmButton.alpha = 0.0;
[self sendRegistrationRequestConfirm:YES];
#pragma mark - Communication
- (void)sendConnectionTestRequest
[self initCustomOtherParameters];
_blinking = YES;
[self setMessageLabelString:NSLocalizedString(@"StartRegistration", nil)];
[self.dataManager sendRequestCommand:kConnectionTest];
- (void)sendRegistrationRequestConfirm:(BOOL)Confirm
[self setMessageLabelString:NSLocalizedString(@"StartRegistration", nil)];
NSString *registrationResult = [self.dataManager RegisterTheUSER_Confirm:Confirm];
[self processLogInResult:registrationResult];
- (void)processLogInResult:(NSString *)logInResult
if ([logInResult isEqual:@"1"]) {
if ([self.dataManager DataInitialization]) {
[self.dataManager DataInitializationForFakeUser];
[self.singlePatient SavePatient];
[self startTherapyButtonDidClicked:nil];
else if ([logInResult isEqual:@"2"]) {
if ([self.dataManager DataInitialization]) {
self.singlePatient.record7_AuthenticatedUser = YES;
[self.singlePatient SavePatient];
[self.dataManager sendRequestCommand:kNewDataAvailable];
else if ([logInResult intValue] == DEVICE_NOT_REGISTERED){
logInResult = NSLocalizedString(@"105", nil);
_blinking = NO;
[self setMessageLabelString:logInResult];
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha
self.ConfirmButton.alpha = 1.0;
else if ([logInResult isEqualToString:kNO]){
_blinking = NO;
[self setMessageLabelString:@"Cannot find the Error "];
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha
_blinking = NO;
[self setMessageLabelString:logInResult];
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha
- (void)downloadZipFile
self.demoProgressView.progressView.progress = 1.0;
sleep(0.4);
[self setMessageLabelString:NSLocalizedString(@"Loading Data", nil)];
self.demoProgressView.progressView.progress = 0.0;
self.dataManager.blockProcessingDataPercentAge = ^(float percentAge, NSString *fileName){
if ([fileName isEqualToString:kaderenzainfo]) {
[[SingletonOperationQueue mainQueue] addOperationWithBlock:^{
self.demoProgressView.progressView.progress = percentA
NSLog(@"%f", percentAge);
if (percentAge == 0.5) {
sleep(0.4);
NSString *aderenzainfoFilePath =
[[NSUserDefaults standardUserDefaults] objectForKey:kaccertamentiinfo];
[self.dataManager downloadZipFile:aderenzainfoFilePath fileName:kaccertamentiinfo];
else if ([fileName isEqualToString:kaccertamentiinfo]){
[[SingletonOperationQueue mainQueue] addOperationWithBlock:^{
self.demoProgressView.progressView.progress = 0.5 + percentA
if (0.5 + percentAge &= 1.0) {
_blinking = NO;
self.CancelButton.alpha = 1.0;
if ([Patient getPatient].record_patientStatus == PatientStatusSuspendedType) {
[self setMessageLabelString:NSLocalizedString(@"SuspendedPatient", nil)];
else if ([Patient getPatient].record_patientStatus == PatientStatusDeletedType){
[self setMessageLabelString:NSLocalizedString(@"DeletedPatient", nil)];
else if ([Patient getPatient].record_patientStatus == PatientStatusActiveType){
[self setMessageLabelString:NSLocalizedString(@"SuccessfulSynchronized", nil)];
self.startTherapyButton.alpha = 1.0;
NSString *aderenzainfoFilePath =
[[NSUserDefaults standardUserDefaults] objectForKey:kaderenzainfo];
[self.dataManager downloadZipFile:aderenzainfoFilePath fileName:kaderenzainfo];
#pragma mark - DataManagerDelegate
- (void)CommunicationConnectionTest:(BOOL)connected
if (connected) {
[self sendRegistrationRequestConfirm:NO];
[self setMessageLabelString:NSLocalizedString(@"connectionTestFail", nil)];
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha
_blinking = NO;
- (void)CommunicationSendRequestCommandName:(NSString *)commandName
if ([commandName isEqualToString:kNewDataAvailable]) {
[self setMessageLabelString:NSLocalizedString(@"Synchronizing", nil)];
- (void)CommunicationReceiveResponseWithOKCommandName:(NSString *)commandName
- (void)CommunicationReceiveResponseWithRequestError:(NSString *)commandName
[self setMessageLabelString:NSLocalizedString(@"NetworkConnectionError", nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha
- (void)CommunicationReceiveResponseCommandName:(NSString *)commandName WithErrorCode:(int)errorCode withErrorDescription:(NSString *)errorDescription
[self setMessageLabelString:NSLocalizedString(@"NewDataAvaiableErrorCode", nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha
-(void)CommunicationZipFileFailDownload
[self setMessageLabelString:NSLocalizedString(@"ZipFileDownloadFail", nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha
-(void)CommunicationZipFileIsNotReadAble
[self setMessageLabelString:NSLocalizedString(@"ZipFileUnzippedFail", nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^{
self.CancelButton.alpha
解决方案 I solved it finally
Inside my Encryption and Decryption function, I have this:
Byte *buffer
= (Byte*)malloc(asciiDataLength);
After I processed with buffer, I convert it to NSData:
NSData *plainData = [NSData dataWithBytesNoCopy:buffer length:asciiDataLength freeWhenDone:YES];
This code causes my app crushes continuously, I changed it to
NSData *plainData = [NSData dataWithBytes:buffer length:asciiDataLength];
free(buffer);
Then my app never crush again.
So, I have to free the Byte by myself, ARC will not free it for me.
本文地址: &
我的应用程式在模拟器上完全运行。 但是当我在设备上运行它来测试时,应用程序崩溃。
显示的错误:
“对象的malloc:*错误0x:从空闲列表中出队的指针无效*在malloc_error_break中设置断点以调试”;
有时会发生另一个错误:
“Thread 6 com.apple.NSURLConnectionLoader:Program received signal:EXC_BAD_ACCESS”
这两个错误是随机的,它会在应用运行两三分钟后发生。
我搜索Google并找到一些解决方案。 它说,在malloc_error_break中设置一个断点来调试,但这只能在模拟器上工作。即使我设置malloc_error_break,应用程序仍然粉碎,它不显示任何东西,我只能看到该错误消息。
这是一个大项目,我真的不知道代码的哪部分导致问题和我需要发布的代码的哪部分。 但我有一个类,我的'SynchroningView'的怀疑。 如果只有我的应用程序与服务器同步,将显示此视图。
这里是我的SynchroningView类:
“SynchroningView.h”
#import& UIKit / UIKit.h&
@class SynchroningV
@protocol SynchroningViewDelegate
- (void)SynchroningViewCancelButtonDidClicked:(SynchroningView *)synchroningV
- (void)SynchroningViewStartTherapyButtonDidClicked:(SynchroningView *)synchroningV
@interface SynchroningView:UIView& DataManagerDelegate&
@property(nonatomic,assign)id& SynchroningViewDelegate& delegateC
@property(nonatomic,retain)UIButton * containerB
@property(nonatomic,retain)Patient * singleP
- (instancetype)initWithFrame:(CGRect)
- (void)showInView:(UIView *)
- (void)dismissMenuP
SynchroningView.m
#import“SDDemoItemView.h” #import“SDPieLoopProgressView.h”
#定义Directory_Document [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES)objectAtIndex:0]
的#define FileName_Image_SynchroningView_BackGroundImageName @“SynchroningView_BackGroundImage” 的#define FilePath_Image_SynchroningView_BackGroundImageName [Directory_Document stringByAppendingPathComponent:FileName_Image_SynchroningView_BackGroundImageName]
@interface SynchroningView()
@property(非原子,强)DataManager * dataM
@property(nonatomic,retain)UILabel * messageL
@property(nonatomic,retain)UIButton * CancelB
@property(nonatomic,retain)CoolButton * ConfirmB
@property(nonatomic,retain)CoolButton * startTherapyB
@property(nonatomic,strong)SDDemoItemView * demoProgressV
@interface SynchroningView() { BOOL _
NSTimer * }
@implementation SynchroningView
- (void)dealloc
{ } b $ b //获取背景图片,使其模糊化并保存。这样我不必使用Blur函数everytim,我直接使用blured图像
- (UIImage *)getBackGroundImage
{ NSFileManager * fileManager = [NSFileManager defaultManager];
if([fileManager fileExistsAtPath:FilePath_Image_SynchroningView_BackGroundImageName]){ return [UIImage imageWithContentsOfFile:FilePath_Image_SynchroningView_BackGroundImageName]; }
else { UIImage * backImage = [UIImage imageWithContentsOfFile:kBackgroundImagePath];
backImage = [backImage blurWithFloat:20.0f];
NSData * binaryImageData = UIImagePNGRepresentation(backImage);
if([binaryImageData writeToFile:FilePath_Image_SynchroningView_BackGroundImageName atomically:YES]){ return backI } }
return [UIImage imageWithContentsOfFile:kBackgroundImagePath]; }
- (instancetype)initWithFrame:(CGRect)frame
{ self = [super initWithFrame:frame];
if(self){
_blinking = NO;
self.dataManager = [[DataManager alloc] init];
self.dataManager.DelegateCustom =
self.backgroundColor = [UIColor clearColor];
self.containerButton = [[UIButton alloc] init];
[self.containerButton setBackgroundColor:RGBA_Custom(0,0,0,0.6f)];
[self.containerButton setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin];
UIView * shadowView = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.frame.size.width,self.frame.size 。高度)];
[self addSubview:shadowView];
shadowView.backgroundColor = RGBA_Custom(230,249,251,0.96f);
// shadowView.layer.borderWidth = 2 * IPAD;
// shadowView.layer.borderColor = [RGBA_Custom(199,199,199,1.0f)CGColor];
shadowView.layer.shadowColor = [UIColor blackColor] .CGC
shadowView.layer.shadowOpacity = 0.4;
shadowView.layer.shadowRadius = 4 * IPAD;
shadowView.layer.shadowOffset = CGSizeMake(4.0f * IPAD,4.0f * IPAD);
shadowView.layer.cornerRadius = 6 * IPAD;
shadowView.userInteractionEnabled = NO;
UIImageView * backGround = [[UIImageView alloc] initWithImage:[self getBackGroundImage]];
backGround.frame = CGRectMake(0,0,shadowView.frame.size.width,shadowView.frame.size.height);
backGround.backgroundColor = [UICcolor clearColor];
[shadowView addSubview:backGround];
backGround.layer.cornerRadius = shadowView.layer.cornerR
backGround.layer.masksToBounds = YES;
ImageWIDTH_ = self.frame.size.height * 0.3;
self.demoProgressView = [SDDemoItemView demoItemViewWithClass:[SDPieLoopProgressView class]];
self.demoProgressView.frame = CGRectMake((self.frame.size.width
ImageWIDTH _)/ 2, kFromLeft, ImageWIDTH_, ImageWIDTH_);
[self addSubview:self.demoProgressView];
self.messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(kFromLeft, self.demoProgressView.frame.origin.y + self .demoProgressView.frame.size.height + kFromLeft, self.frame.size.width
kFromLeft * 2, self.frame.size.height
- (self.demoProgressView.frame.origin.y + self.demoProgressView.frame.size.height + kFromLeft * 2))];
self.messageLabel.backgroundColor = [UIColor clearColor];
self.messageLabel.textColor = [UIColor blackColor];
self.messageLabel.textAlignment = NSTextAlignmentC
self.messageLabel.numberOfLines = 0;
self.messageLabel.lineBreakMode = NSLineBreakByWordW
self.messageLabel.font = [UIFont boldSystemFontOfSize:kIPAD? 20:12];
self.messageLabel.text = @“”;
self.messageLabel.adjustsFontSizeToFitWidth = YES;
[self addSubview:self.messageLabel];
CGFloat BtnHeight = kIPAD? 40:30;
self.CancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.CancelButton.frame = CGRectMake(self.frame.size.width
kFromLeft * 0.5
BtnHeight, kFromLeft * 0.5, BtnHeight, BtnHeight);
self.CancelButton.backgroundColor = [UIColor clearColor];
[self.CancelButton setImage:[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@“utilities_close”ofType:@“png”]] forState:UIControlStateNormal];
[self.CancelButton addTarget:self action:@selector(pressCancelButton :) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.CancelButton];
BtnHeight = kIPAD? 70:50;
CGFloat BtnWidth = self.frame.size.width / 4;
NSString * ConfirmButtonStr = NSLocalizedString(@“Confirm”,nil);
ExpectedSize = [ConfirmButtonStr sizeWithFont:self.messageLabel.font constrainedToSize:CGSizeMake(VIEW_WIDTH,BtnHeight)lineBreakMode:NSLineBreakByWordWrapping];
ExpectedSize = CGSizeMake(ExpectedSize.width + 30 * IPAD,ExpectedSize.height);
self.ConfirmButton = [CoolButton buttonWithType:UIButtonTypeCustom];
self.ConfirmButton.frame = CGRectMake((self.frame.size.width
ExpectedSize.width)/ 2, self.frame.size.height
kFromLeft, ExpectedSize。 width, BtnHeight);
self.ConfirmButton.titleLabel.font = self.messageLabel.
[self.ConfirmButton setTitle:ConfirmButtonStr forState:UIControlStateNormal];
[self.ConfirmButton addTarget:self action:@selector(pressConfirmButton :) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.ConfirmButton];
BtnWidth = self.frame.size.width * 0.6;
NSString * startTherapyButtonStr = NSLocalizedString(@“StartTerapia”,nil);
ExpectedSize = [startTherapyButtonStr sizeWithFont:self.messageLabel.font constrainedToSize:CGSizeMake(VIEW_WIDTH,BtnHeight)lineBreakMode:NSLineBreakByWordWrapping];
ExpectedSize = CGSizeMake(ExpectedSize.width + 30 * IPAD,ExpectedSize.height);
self.startTherapyButton = [CoolButton buttonWithType:UIButtonTypeCustom];
self.startTherapyButton.frame = CGRectMake((self.frame.size.width
ExpectedSize.width)/ 2, self.ConfirmButton.frame.origin.y, ExpectedSize.width,
self.ConfirmButton.frame.size.height);
self.startTherapyButton.titleLabel.font = self.messageLabel.
[self.startTherapyButton setTitle:startTherapyButtonStr forState:UIControlStateNormal];
[self.startTherapyButton addTarget:self action:@selector(startTherapyButtonDidClicked :) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.startTherapyButton];
self.CancelButton.alpha = 0.0;
self.ConfirmButton.alpha = 0.0;
self.startTherapyButton.alpha = 0.0;
if(self.dataManager.firstSynchronizationAgain == 1&& [AccessedInfo getAccessedInfo]){ UILabel * alertInfoLabel = [[UILabel alloc] initWithFrame:CGRectMake(kFromLeft, 0, self.frame.size.width
kFromLeft * 2, VIEW_HEIGHT)];
alertInfoLabel.backgroundColor = [UIColor clearColor];
alertInfoLabel.textColor = COLOR_CIRCLE;
alertInfoLabel.textAlignment = NSTextAlignmentC
alertInfoLabel.numberOfLines = 0;
alertInfoLabel.lineBreakMode = NSLineBreakByWordW
alertInfoLabel.font = [UIFont systemFontOfSize:self.startTherapyButton.titleLabel.font.pointSize-2];
alertInfoLabel.text = NSLocalizedString(@“SynchronizingNew”,nil);
ExpectedSize = [alertInfoLabel.text sizeWithFont:alertInfoLabel.font constrainedToSize:alertInfoLabel.frame.size lineBreakMode:NSLineBreakByWordWrapping];
alertInfoLabel.frame = CGRectMake(alertInfoLabel.frame.origin.x, self.startTherapyButton.frame.origin.y
ExpectedSize.height
IPAD * 2, alertInfoLabel.frame.size。 width, ExpectedSize.height);
[self addSubview:alertInfoLabel];
[self.containerButton addSubview:self]; }
//显示同步结果消息
- (void)setMessageLabelString:(NSString *)labelName
{ self.messageLabel.text = labelN
ExpectedSize = [labelName sizeWithFont:self.messageLabel.font constrainedToSize:CGSizeMake(self.messageLabel.frame.size.width,VIEW_HEIGHT)lineBreakMode:NSLineBreakByWordWrapping];
self.messageLabel.frame = CGRectMake(self.messageLabel.frame.origin.x, self.messageLabel.frame.origin.y, self.messageLabel.frame.size.width,
ExpectedSize.height);
timer = [NSTimer scheduledTimerWithTimeInterval:0.8 target:self selector:@selector(MessageLabelBlinking)userInfo:nil repetes:YES];
// self.messageLabel.adjustsFontSizeToFitWidth = YES; }
- (void)MessageLabelBlinking
{ if(_blinking){ NSString * threeDot = @“.....”;
if([self.messageLabel.text rangeOfString:threeDot] .location == NSNotFound){ self.messageLabel.text = [self.messageLabel.text stringByAppendingString:@“。”]; }
else { self.messageLabel.text = [self.messageLabel.text stringByReplacingOccurrencesOfString:threeDot withString:@“”]; } }
else { [timer invalidate];
timer = } }
//如果您执行自定义绘图,则只覆盖drawRect:。
//空白实现会影响动画期间的性能。
- (void)drawRect:(CGRect)rect { //绘图代码}
//初始化数据处理块
- (void)initCustomOtherParameters
{ self.dataManager.DelegateCustom =
self.dataManager.blockProcessingData = ^(float allCommand,float restCommand){ if(allCommand == 0){ [[SingletonOperationQueue mainQueue] addOperationWithBlock:^ { self.demoProgressView.progressView.progress = 1;
NSString * messageStr = [NSLocalizedString(@“SuccessfulSynchronized”,nil)stringByAppendingFormat:@“\\\%@”,NSLocalizedString(@“EmptyTherapy”,nil)];
[self setMessageLabelString:messageStr];
_blinking = NO;
self.CancelButton.alpha = 1.0; }]; }
else { float percenAger =(restCommand / allCommand);
percenAger = 1
[[SingletonOperationQueue mainQueue] addOperationWithBlock:^ { self.demoProgressView.progressView.progress = percenA
if(restCommand == 0){ [self downloadZipFile]; } }]; } };
[Patient RemovePatient];
[self.singlePatient SavePatient]; }
- (void)showInView:(UIView *)view
{ self.transform = CGAffineTransformScale(self.transform,0.8,0.8);
self.containerButton.alpha = 0.0f;
self.containerButton.frame = view.
[view addSubview:self.containerButton];
[UIView animateWithDuration:0.15 animations:^ { self.containerButton.alpha = 1.0f;
self.transform = CGAffineTransformScale(self.transform,1.4,1.4);
}完成:^(BOOL完成){ if(finished){ [UIView animateWithDuration:0.20 animations:^ { self.transform = CGAffineTransformI }];
[self sendConnectionTestRequest]; }
else { self.transform = CGAffineTransformI
[self sendConnectionTestRequest]; } }]; }
- (void)dismissMenuPopover
{ [self hide]; }
- (void)hide
{ [UIView animateWithDuration:0.25 animations:^ { self.transform = CGAffineTransformScale(self.transform,0.8,0.8) ;
self.containerButton.alpha = 0.0f; } completion:^(BOOL finished){ if(finished){ [self.containerButton removeFromSuperview]; } }]; }
- (void)pressCancelButton:(UIButton *)button
{ [self.dataManager CommunicationCancel];
[self.delegateCustom SynchroningViewCancelButtonDidClicked:self]; }
- (void)startTherapyButtonDidClicked:(UIButton *)button
{ [self.delegateCustom SynchroningViewStartTherapyButtonDidClicked:self]; }
- (void)pressConfirmButton:(UIButton *)button
{ [UIView animateWithDuration:0.25 animations:^ { self.CancelButton.alpha = 0.0;
self.ConfirmButton.alpha = 0.0; }];
[self sendRegistrationRequestConfirm:YES]; }
#pragma mark
Communication
- (void)sendConnectionTestRequest
{ [self initCustomOtherParameters];
_blinking = YES;
[self setMessageLabelString:NSLocalizedString(@“StartRegistration”,nil)];
[self.dataManager sendRequestCommand:kConnectionTest]; }
- (void)sendRegistrationRequestConfirm:(BOOL)确认 { [self setMessageLabelString:NSLocalizedString(@“StartRegistration”,nil)
NSString * registrationResult = [self.dataManager RegisterTheUSER_Confirm:Confirm];
[self processLogInResult:registrationResult]; }
- (void)processLogInResult:(NSString *)logInResult
{ if([logInResult isEqual:@“1”]){ if .dataManager DataInitialization]){ [self.dataManager DataInitializationForFakeUser];
[self.singlePatient SavePatient];
[self startTherapyButtonDidClicked:nil]; } }
else if([logInResult isEqual:@“2”]){ if([self.dataManager DataInitialization]){ self.singlePatient。 record7_AuthenticatedUser = YES;
[self.singlePatient SavePatient];
[self.dataManager sendRequestCommand:kNewDataAvailable]; }; }
else if([logInResult intValue] == DEVICE_NOT_REGISTERED){ logInResult = NSLocalizedString(@“105”,nil);
_blinking = NO;
[self setMessageLabelString:logInResult];
[UIView animateWithDuration:0.25 animations:^ { self.CancelButton.alpha = 1.0;
self.ConfirmButton.alpha = 1.0; }]; }
else if([logInResult isEqualToString:kNO]){ _blinking = NO;
[self setMessageLabelString:@“找不到错误”];
[UIView animateWithDuration:0.25 animations:^ { self.CancelButton.alpha = 1.0; }]; }
else { _blinking = NO;
[self setMessageLabelString:logInResult];
[UIView animateWithDuration:0.25 animations:^ { self.CancelButton.alpha = 1.0; }]; } }
- (void)downloadZipFile
{ self.demoProgressView.progressView.progress = 1.0;
sleep(0.4);
[self setMessageLabelString:NSLocalizedString(@“Loading Data”,nil)];
self.demoProgressView.progressView.progress = 0.0;
self.dataManager.blockProcessingDataPercentAge = ^(float percentAge,NSString * fileName){
if([fileName isEqualToString:kaderenzainfo]){ [SingletonOperationQueue mainQueue] addOperationWithBlock: { self.demoProgressView.progressView.progress = percentA
NSLog(@“%f”,percentAge);
if(percentAge == 0.5){ sleep(0.4);
NSString * aderenzainfoFilePath = [[NSUserDefaults standardUserDefaults] objectForKey:kaccertamentiinfo];
[self.dataManager downloadZipFile:aderenzainfoFilePath fileName:kaccertamentiinfo]; } }]; }
else if([fileName isEqualToString:kaccertamentiinfo]){ [[SingletonOperationQueue mainQueue] addOperationWithBlock:^ { self.demoProgressView.progressView.progress = 0.5 + percentA
if(0.5 + percentAge& = 1.0){
_blinking = NO;
self.CancelButton.alpha = 1.0;
if([Patient getPatient] .record_patientStatus == PatientStatusSuspendedType){ [self setMessageLabelString:NSLocalizedString(@“SuspendedPatient”,nil)]; }
else if([Patient getPatient] .record_patientStatus == PatientStatusDeletedType){ [self setMessageLabelString:NSLocalizedString(@“DeletedPatient”,nil)]; }
else if([Patient getPatient] .record_patientStatus == PatientStatusActiveType){ [self setMessageLabelString:NSLocalizedString(@“SuccessfulSynchronized”,nil)];
self.startTherapyButton.alpha = 1.0; } } }]; } };
NSString * aderenzainfoFilePath = [[NSUserDefaults standardUserDefaults] objectForKey:kaderenzainfo];
[self.dataManager downloadZipFile:aderenzainfoFilePath fileName:kaderenzainfo]; }
#pragma mark
DataManagerDelegate
- (void)CommunicationConnectionTest:(BOOL)connected
{ if(connected){ [self sendRegistrationRequestConfirm:没有]; }
else { [self setMessageLabelString:NSLocalizedString(@“connectionTestFail”,nil)];
[UIView animateWithDuration:0.25 animations:^ { self.CancelButton.alpha = 1.0; }];
_blinking = NO; } }
- (void)CommunicationSendRequestCommandName:(NSString *)commandName
{ if([commandName isEqualToString:kNewDataAvailable]){ [self setMessageLabelString:NSLocalizedString(@“Synchronizing”,nil)]; } }
- (void)CommunicationReceiveResponseWithOKCommandName:(NSString *)commandName
- (void)CommunicationReceiveResponseWithRequestError :( NSString *)commandName
{ [self setMessageLabelString:NSLocalizedString(@“NetworkConnectionError”,nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^ { self.CancelButton.alpha = 1.0; }]; }
- (void)CommunicationReceiveResponseCommandName:(NSString *)commandName WithErrorCode:(int)errorCode withErrorDescription:(NSString *)errorDescription
{ [self setMessageLabelString:NSLocalizedString NewDataAvaiableErrorCode“,nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^ { self.CancelButton.alpha = 1.0; }]; }
- (void)CommunicationZipFileFailDownload
{ [self setMessageLabelString:NSLocalizedString(@“ZipFileDownloadFail”,nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^ { self.CancelButton.alpha = 1.0; }]; }
- (void)CommunicationZipFileIsNotReadAble
{ [self setMessageLabelString:NSLocalizedString(@“ZipFileUnzippedFail”,nil)];
_blinking = NO;
[UIView animateWithDuration:0.25 animations:^ { self.CancelButton.alpha = 1.0; }]; }
解决方案 我最终解决了它
在我的加密和解密函数中,我有:
Byte * buffer =(Byte *)malloc(asciiDataLength);
使用缓冲区处理后,我将其转换为NSData:
NSData * plainData = [NSData dataWithBytesNoCopy:buffer length:asciiDataLength freeWhenDone:YES];
此代码导致我的应用程序连续崩溃,我将其更改为
NSData * plainData = [NSData dataWithBytes:buffer length:asciiDataLength];
free(buffer);
然后我的应用程式永远不会再次崩溃。
所以,我必须自己释放字节,ARC不会为我释放。
本文地址: &
扫一扫关注官方微信}

我要回帖

更多关于 dequeueitemfromlist 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信