1

在 IOS3 下运行良好的 iPad 应用程序在 IOS4.2 下失败。它有一个类从操作队列运行 http 会话,并且失败与此活动相关联。这是控制台输出:

Program received signal:  “EXC_BAD_ACCESS”.
[Switching to thread 11523]

运行 NSZombies 启用并没有显示任何内容,因此我一直将 NSLog 语句放入代码中,发现当局部变量更改时会发生崩溃。这是代码部分:

self.currentOperation = [[[DeduceAccessOperation alloc] init] autorelease];
[self.currentOperation addObserver:self forKeyPath:@"isFinished"
 options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld)
 context:NULL];
NSLog (@"Start observer added");    
[operationQueue addOperation:self.currentOperation];
NSLog (@"Start operation added");
NSLog(@"State is %d", self.status);
self.status = IEnablerServiceUpdating;
NSLog (@"State updated");

这是控制台日志输出:

2010-12-08 21:26:44.548 UCiEnabler[5180:307] Start observer added
2010-12-08 21:26:44.550 UCiEnabler[5180:307] Start operation added
2010-12-08 21:26:44.552 UCiEnabler[5180:307] State is 1
Program received signal:  “EXC_BAD_ACCESS”.
[Switching to thread 11523]

就像状态已变为只读(它的属性被声明为原子和读写)。

另一条相关信息是子视图刚刚被更改,它触发了对上述例程的调用。它的代码是:

//Start the update      
UCiEnablerAppDelegate *controller = (UCiEnablerAppDelegate *)[[UIApplication sharedApplication] delegate];
[controller deduceIEnablerServiceAccess];
controller.serviceBusy = TRUE; //1.04

有没有人见过这样的事情?

有没有人知道下一步该往哪里看?

问候罗宾

这是堆栈跟踪:

#0  0x34a80464 in objc_msgSend
#1  0x3119543e in NSKVOPendingNotificationCreate
#2  0x3119535a in NSKeyValuePushPendingNotificationPerThread
#3  0x3117009a in NSKeyValueWillChange
#4  0x311682c6 in -[NSObject(NSKeyValueObserverNotification) willChangeValueForKey:]
#5  0x311cc718 in _NSSetIntValueAndNotify
#6  0x000097ce in -[IEnablerService startDeducingAccessState] at IEnablerService.m:55
#7  0x00002bc0 in -[UCiEnablerAppDelegate deduceIEnablerServiceAccess] at UCiEnablerAppDelegate.m:100
#8  0x0000a33e in -[RootViewControlleriPad animationDidStop:finished:context:] at RootViewController-iPad.m:43
#9  0x341bb336 in -[UIViewAnimationState sendDelegateAnimationDidStop:finished:]
4

1 回答 1

0

NSOperationQueue在 iOS 4.2 中,现在开始时使用 GrandCentralDispatch NSOperations这里有技术问答

现在,无论属性如何,队列几乎都在新线程中调用NSOperation子类的方法。根据我的经验,这意味着如果您在方法内部使用,您的代码将不再运行,因为正在运行的线程没有.startisConcurrentNSURLConnectionstartstartNSRunLoop

Apple 表示此更改不会破坏兼容性,因为start无论如何您都应该在该方法中生成一个新线程。

为了向后兼容,您应该将子类从 using 更改start为 using run

于 2010-12-08T12:38:21.987 回答