Hey..i在可可下面的方法..解决可可中的EXC_BAD_ACCESS问题?
-(void)startUploadWithContainerName:(NSString *)containerName
{
//Make an object of NSFileManager and Fetch an array of local folder contents and cloud folder contents
NSFileManager *uploadManager=[[NSFileManager alloc] init];
NSString *uploadPath=[[[NSString alloc] initWithString:@"~/Cloud Briefcase"] stringByExpandingTildeInPath];
NSError *err;
NSArray *uploadFolderContents=[uploadManager contentsOfDirectoryAtPath:uploadPath error:&err];
ASICloudFilesObjectRequest *cloudList = [ASICloudFilesObjectRequest listRequestWithContainer:containerName];
[cloudList startSynchronous];
NSArray *cloudFolderContents = [cloudList objects];
[cloudList release];
[uploadManager release];
NSLog(@"%lu",[uploadFolderContents count]);
NSLog(@"\n%@\n\n%@",cloudFolderContents,uploadFolderContents);
NSString *notFoundPath;
NSString *foundPath;
NSString *foundCloudMatch;
NSDate *cloudUploadDate;
for (int j=1; j<[uploadFolderContents count]; j++) {
int i=0;
for (int k=0; k<[cloudFolderContents count]; k++) {
if ([[[cloudFolderContents objectAtIndex:k] name] isEqualToString:[uploadFolderContents objectAtIndex:j]]) {
i=1;
foundPath=[uploadFolderContents objectAtIndex:j];
foundCloudMatch=[cloudFolderContents objectAtIndex:k];
cloudUploadDate=[[cloudFolderContents objectAtIndex:k] lastModified];
break;
}
else{
i=0;
notFoundPath=[uploadFolderContents objectAtIndex:j];
continue;
}
}
if (i==1) {
NSLog(@"Found In Cloud: %@",foundPath);
NSString *uploadPath=[[NSString stringWithFormat:@"~/Cloud Briefcase/%@",foundPath] stringByExpandingTildeInPath];
NSTimeZone *tCST=[NSTimeZone timeZoneWithAbbreviation:@"CST"];
NSInteger cloudDifference=[tCST secondsFromGMTForDate:cloudUploadDate];
NSFileManager *typeManager=[[NSFileManager alloc] init];
NSError *Er;
NSDictionary *propertiesOfUploadFile=[typeManager attributesOfItemAtPath:uploadPath error:&Er];
NSDate *localUploadDate=[propertiesOfUploadFile objectForKey:NSFileModificationDate];
NSInteger sourceUploadDifference=[[NSTimeZone systemTimeZone] secondsFromGMTForDate:localUploadDate];
NSLog(@"Local Date %@",localUploadDate);
NSLog(@"Local Difference %ld",sourceUploadDifference);
NSTimeInterval diff=sourceUploadDifference-cloudDifference;
NSTimeInterval sDiff=sourceUploadDifference;
NSDate *lDate=[[NSDate alloc] initWithTimeInterval:sDiff sinceDate:localUploadDate];
NSDate *comparisonDate=[[NSDate alloc] initWithTimeInterval:diff sinceDate:cloudUploadDate];
NSLog(@"\nSDiff Value %@",lDate);
NSLog(@"Comparison Date %@",comparisonDate);
[localUploadDate release];
[propertiesOfUploadFile release];
[typeManager release];
[tCST release];
if ([comparisonDate compare:lDate]==NSOrderedAscending) {
[comparisonDate release];
[lDate release];
NSLog(@"Got It");
NSString *escString=[foundPath stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
ASICloudFilesObjectRequest *request =
[ASICloudFilesObjectRequest putObjectRequestWithContainer:containerName objectPath:escString contentType:@"file" file:uploadPath metadata:nil etag:nil];
[request startSynchronous];
NSLog(@"Uploaded %@",foundPath);
}
}
else{
NSLog(@"Not Found In Cloud: %@",notFoundPath);
NSString *uploadPath=[[NSString stringWithFormat:@"~/Cloud Briefcase/%@",notFoundPath] stringByExpandingTildeInPath];
// NSLog(@"%@",uploadPath);
NSString *escString=[notFoundPath stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSLog(@"URL ENCODED VALUE: %@",escString);
ASICloudFilesObjectRequest *request =
[ASICloudFilesObjectRequest putObjectRequestWithContainer:containerName objectPath:escString contentType:@"file" file:uploadPath metadata:nil etag:nil];
[request startSynchronous];
NSLog(@"Upload Complete");
}
}
[uploadPath release];
[cloudList release];
[uploadFolderContents release];
}
但它挂出异常
接收信号EXC_BAD_ACCESS
任何人都可以清除问题出来吗?在NSLog(@“Found In Cloud:%@”,foundPath)发生异常;
它解决了例外在于method..but它导致相同的异常在main.m文件 #进口<可可/ Cocoa.h> INT主(INT的argc,字符* argv的[]){ return NSApplicationMain(argc,(const char **)argv); } 返回NSApplica .....线似乎已经捕捉到的异常.. – proctr
@twistedcerebrum考虑重构你的代码,请。方法的本地变量与变量本地的相同名称与if块或块的名称相同。使我们难以阅读您的代码。你的应用崩溃了什么? EXC_BAD_ACCESS?当你在调试模式下运行断点时,它会显示控制停在main方法中,它的正常并不意味着你需要修复main方法。它的原因是你捣毁了堆栈,所以它找不到当前函数的框架,或者它实际上停在另一个线程中。 – 0x8badf00d
好man..made sense..thnx .. – proctr