我的申请功能是把手工艺从两个单人之间转移。
The user can choose lots of pic to send. But since the send process need time, so right now I just put the pics that have not yet been sent into an array when the user picks it from the photo-library.
我现在的问题是,如果用户在一个时间选择太多的剂量,我的申请就会突然终止。 现在,我的解决办法是,如果用户在某一时间选择太多的剂量,那么我就只能把标记放在某些手法上,而把他们放在光图书馆里,同时把他们放在阵列中。 然后,我又在发送行动同时从图书馆装上手工艺品。 因此,我在此指出,我怀疑,如此多的论题被放在一阵列中,是申请终止的原因,因此,我想把一些论题放在磁盘上,然后把其他部分放在磁盘上,我的代码是:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(alertView.tag == 100)
{
if (buttonIndex == 1)
{
inArray = YES;
NSLog(@"---------%d",[self.imageArr count]);
if ([self.imageArr count] < kCachedImages) {
[self.imageArr addObject:thisImageObj];
[thisImageObj release];
}
else
[self.imageURLArr addObject:photoURL];
if(!isSending)
{
currentPos = -1;
[self sendImage];
}
[sndTableView reloadData];
}
else if (buttonIndex == 2)
{
if (inArray) {
if ([self.imageArr count] < kCachedImages) {
[self.imageArr addObject:thisImageObj];
[thisImageObj release];
}else {
[self.imageURLArr addObject:photoURL];
}
}else {
[self.imageArr addObject:thisImageObj];
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
[self.popOverView dismissPopoverAnimated:YES];
}
else {
[self dismissModalViewControllerAnimated:YES];
}
[sndTableView reloadData];
if(!isSending)
{
currentPos = -1;
[self sendImage];
}
}
}
}
- (void)sendImage
{
if(![self.imageArr count])
{
[[UIApplication sharedApplication] setIdleTimerDisabled:NO];
isSending = NO;
[self.navigationItem setHidesBackButton:NO animated:YES];
return; //end of all sending
}
NSMutableData *toBeSend = [NSMutableData dataWithCapacity:sizeof(packetHeader)+kBuffer];
imageObj *imgObj;
if ([self.imageArr count]) {
imgObj = [[self.imageArr objectAtIndex:0]retain];
}
//here created another thread to load pics from library
if ([self.imageURLArr count] > 0) {
[NSThread detachNewThreadSelector:@selector(load) toTarget:self withObject:nil];
}
packetHeader header;
header.magic = 0x5577ACAC;
header.seq = currentSeq++;
if(currentPos < 0) //first packet
{
UIImage *img = [UIImage imageWithData:imgObj.pimage];
self.currentSendingImg.image = img;
//thumbnail
img = [TransferViewController imageWithImage:img scaledToSize:CGSizeMake(70, 70)];
NSData *data = UIImageJPEGRepresentation(img, 0.5);
header.command = 16;
header.commandData1 = imgObj.imageSize;
header.commandData2 = (imgObj.imageWidth<<16) + imgObj.imageLength;
header.commandData3 = [data length];
// NSLog(@"thumbnail data length = %u", header.commandData3);
[toBeSend appendData:[NSData dataWithBytes:&header length:sizeof(packetHeader)]];
[toBeSend appendData:data];
currentPos = 0;
isSending = YES;
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
[self.navigationItem setHidesBackButton:YES animated:YES];
}
else
{
if(currentPos + kBuffer < imgObj.imageSize)
{
header.command = 19;
header.commandData1 = kBuffer;
[toBeSend appendData:[NSData dataWithBytes:&header length:sizeof(packetHeader)]];
NSRange r;
r.location = currentPos;
r.length = kBuffer;
[toBeSend appendData:[imgObj.pimage subdataWithRange:r]];
currentPos += kBuffer;
}
else
{//last packet
header.command = 17;
header.commandData1 = imgObj.imageSize - currentPos;
[toBeSend appendData:[NSData dataWithBytes:&header length:sizeof(packetHeader)]];
NSRange r;
r.location = currentPos;
r.length = header.commandData1;
[toBeSend appendData:[imgObj.pimage subdataWithRange:r]];
currentPos = -1;
if ([self.imageArr count]) {
[self.imageArr removeObjectAtIndex:0];
}
[self.sndTableView reloadData];
}
}
[manager sendPacket:toBeSend];
self.sendingProgess.progress = (float)currentPos / (float)imgObj.imageSize;
[imgObj release];
}
- (void)load
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
if (![imageURLArr count]) {
return;
}
int imageSum = [imageURLArr count];
NSURL *path = [self.imageURLArr objectAtIndex:0] ;
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:path resultBlock:^(ALAsset *asset)
{
ALAssetRepresentation *representation = [asset defaultRepresentation];
CGImageRef ref = [representation fullResolutionImage];
if (ref != nil) {
omg = [UIImage imageWithCGImage:ref];
[omg retain];
}
}
failureBlock:^(NSError *error)
{
// error handling
}];
[library release];
if (omg) {
NSData *data = UIImageJPEGRepresentation(omg, kcompressionQuality);
thisImageObj = [imageObj alloc];
thisImageObj.imageSize = [data length];
thisImageObj.imageWidth = omg.size.width;
thisImageObj.imageLength = omg.size.height;
thisImageObj.pimage = data;
[omg release];
}
else {
return;
}
imageSum--;
if ([self.imageURLArr count]) {
[self.imageURLArr removeObjectAtIndex:0];
}
[self.imageArr addObject:thisImageObj];
[thisImageObj release];
[NSThread sleepForTimeInterval:1.0];
[pool release];
}
但是,现在其他近距离工作的方法,以及已经结束的问题,人们可以就如何做到这一点向我提出一些建议,或者说,根本上需要另一条线。