简体   繁体   English

NSOperation就绪,但无法在iOS 7上启动

[英]NSOperation ready but not starting on iOS 7

We created an operation framework to add some functionality not found in the base classes (eg tracking success/failure). 我们创建了一个操作框架,以添加一些在基类中找不到的功能(例如,跟踪成功/失败)。 Parent operations are usually non-concurrent, and may only exist to manage child operations. 父级操作通常是非并行的,并且只能存在于管理子级操作中。 Child operations which are typically concurrent (downloading xml and media asynchronously). 通常是并发的子操作(异步下载xml和媒体)。

When we run our application on iOS 7, add we a number of operations to the operation queue, ~3/4 of the operations complete, and then the app appears to hang. 当我们在iOS 7上运行我们的应用程序时,将一些操作添加到操作队列中,完成约3/4个操作,然后该应用程序似乎挂起。

When I pause the app in the debugger, and I examine the operations in the queue (sOpQueue.operations), many of them are ready to run (isReady returns TRUE), but apparently none of them are executing (isExecuting returns FALSE, and I see no evidence of any operation running on any thread). 当我在调试器中暂停应用程序,并检查队列中的操作(sOpQueue.operations)时,其中许多已准备好运行(isReady返回TRUE),但显然没有一个正在执行(isExecuting返回FALSE,我看不到任何在任何线程上运行的操作的证据)。

This is a new problem as of iOS 7. 从iOS 7开始,这是一个新问题。

The behavior does not seem to change when I increase or decrease the number of concurrent operations. 当我增加或减少并发操作数时,行为似乎没有改变。

Does anyone have any suggestions on how to determine why a ready operation is not being started? 是否有人对如何确定为什么未开始就绪操作有任何建议?

Thanks, Chuck 谢谢,查克

Are you issuing the isReady Key Value Observing notification? 您是否正在发布isReady 键值观察通知?

For example, I use a property: 例如,我使用一个属性:

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

And then have a custom setter: 然后有一个自定义的setter:

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

As well as a custom getter that calls super : 以及调用super的自定义getter:

- (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 ): 而且,由于您同时实现了setter和getter,因此必须在@implementation的开头手动合成属性(通常不必再执行此操作,但是如果实现所有自定义访问器,则必须手动@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); ready属性设置为YES (请注意,使用setter而不是直接使用ivar);

     self.ready = YES; 

    or 要么

     [self setReady:YES]; 
  • All other standard NSOperation criteria are satisfied (eg dependencies between operations, honoring maxConcurrentOperationCount , factoring in priorities, etc.). 满足所有其他标准NSOperation标准(例如,操作之间的依赖关系,遵守maxConcurrentOperationCount ,考虑优先级等)。

I'll bet you have concurrent operations that haven't finished properly. 我敢打赌,您的并发操作尚未正确完成。 Raise you number of concurrent operations and see if you can run longer before it hangs. 提高并发操作的数量,并查看在挂起之前是否可以运行更长的时间。 Then figure out why your concurrent operations aren't correctly setting isFinished. 然后找出为什么并发操作未正确设置isFinished的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM