3

我们创建了一个操作框架来添加一些在基类中没有的功能(例如跟踪成功/失败)。父操作通常是非并发的,并且可能仅用于管理子操作。子操作通常是并发的(异步下载 xml 和媒体)。

当我们在 iOS 7 上运行我们的应用程序时,将一些操作添加到操作队列中,大约 3/4 的操作完成,然后应用程序似乎挂起。

当我在调试器中暂停应用程序并检查队列中的操作 (sOpQueue.operations) 时,其中许多已准备好运行(isReady 返回 TRUE),但显然它们都没有执行(isExecuting 返回 FALSE,我看不到任何线程上运行任何操作的证据)。

这是 iOS 7 的新问题。

当我增加或减少并发操作的数量时,行为似乎没有改变。

有没有人对如何确定为什么没有开始准备好的操作有任何建议?

谢谢,查克

4

2 回答 2

5

Are you issuing the isReady Key Value Observing notification?

For example, I use a property:

@property (nonatomic, getter = isReady) BOOL ready;

And then have a custom setter:

- (void)setReady:(BOOL)ready
{
    [self willChangeValueForKey:@"isReady"];
    _ready = ready;
    [self didChangeValueForKey:@"isReady"];
}

As well as a custom getter that calls super:

- (BOOL)isReady
{
    return _ready && [super isReady];
}

And, because you implemented both the setter and getter, you have to manually synthesize the property at the beginning of the @implementation (usually you don't have to do this anymore, but if you implement all of the custom accessors, you have to manually @synthesize):

@synthesize ready = _ready;

Then, the operation starts when both of the following conditions are satisfied:

  • The ready property is set to YES (note, use the setter, not the ivar directly);

    self.ready = YES;
    

    or

    [self setReady:YES];
    
  • All other standard NSOperation criteria are satisfied (e.g. dependencies between operations, honoring maxConcurrentOperationCount, factoring in priorities, etc.).

于 2013-10-08T20:43:58.723 回答
2

我敢打赌你有并发操作没有正确完成。增加并发操作的数量,看看是否可以在挂起之前运行更长时间。然后找出为什么你的并发操作没有正确设置 isFinished。

于 2013-10-08T21:12:15.503 回答