Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c NSOperationQueue在ios4的主线程上执行,而不是在io5上执行?_Objective C_Ios_Multithreading_Nsoperationqueue - Fatal编程技术网

Objective c NSOperationQueue在ios4的主线程上执行,而不是在io5上执行?

Objective c NSOperationQueue在ios4的主线程上执行,而不是在io5上执行?,objective-c,ios,multithreading,nsoperationqueue,Objective C,Ios,Multithreading,Nsoperationqueue,是否有任何原因导致NSOperationQueue在ios 4.2.1的主线程上执行,而在ios 5.0.1的单独线程上运行(如预期的那样) 在我的应用程序启动时,我正在使用NSOperationQueue对大量图片(图像集)执行繁忙操作,但它在ios4的主线程上运行,而不是在ios5上运行 这是一段代码 从主线程: cacheManager = [[PicturesCacheManager alloc] initWithDelegate:self]; //start the g

是否有任何原因导致NSOperationQueue在ios 4.2.1的主线程上执行,而在ios 5.0.1的单独线程上运行(如预期的那样)

在我的应用程序启动时,我正在使用NSOperationQueue对大量图片(图像集)执行繁忙操作,但它在ios4的主线程上运行,而不是在ios5上运行

这是一段代码

从主线程:

    cacheManager = [[PicturesCacheManager alloc] initWithDelegate:self];
    //start the generation of the pictures array
    NSLOG(@"setUpToDatePicturesArray");
    operationQueue = [[NSOperationQueue alloc] init];
    [operationQueue addOperation:cacheManager];
    [cacheManager release];
从PictureCacheManager:

- (id)initWithDelegate:(id <CachePicturesProtocol> )delegatePic
{
    self = [super init];
    if (self) {
        // Initialization code here.
        [self setDelegate:delegatePic];
    }

return self;
} 

-(void)main{
    [self loadCurrentCameraRoll]; //do lot of stuff 
}

-(void)loadCurrentCameraRoll{
//NSLOG(@"loadCurrentCameraRoll");
// photos
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
    //photos only!
    if(result != NULL && [[result valueForProperty:@"ALAssetPropertyType"] isEqualToString:@"ALAssetTypePhoto"]) {

        //Do stuff
    }
};

void (^assetGroupEnumerator)( ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {
    if(group != nil) {
        NSLOG(@"current group = %@", group);
        [group enumerateAssetsUsingBlock:assetEnumerator];
    }
    else{
        //we've enumerated all the groups

    }
};

assetsList = [[NSMutableArray alloc] init];
ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];

[library enumerateGroupsWithTypes:ALAssetsGroupAll
                       usingBlock:assetGroupEnumerator
                     failureBlock: ^(NSError *error) {
                         NSLOG(@"Failure : %@", [error description]);
                     }];

}
-(id)initWithDelegate:(id)delegatePic
{
self=[super init];
如果(自我){
//这里是初始化代码。
[自我设置委派:委派PIC];
}
回归自我;
} 
-(无效)主要{
[self-loadCurrentCameraRoll];//做很多事情
}
-(无效)loadCurrentCameraRoll{
//NSLOG(@“loadCurrentCameraRoll”);
//照片
void(^assetEnumerator)(ALAsset*,NSUTEGER,BOOL*)=^(ALAsset*结果,NSUTEGER索引,BOOL*停止){
//仅限照片!
if(result!=NULL&&[[result valueForProperty:@“ALAssetPropertyType”]IseQualString:@“ALAssetTypePhoto”]){
//做事
}
};
void(^assetGroupEnumerator)(AlasSetGroup*,BOOL*)=^(AlasSetGroup*组,BOOL*停止){
如果(组!=nil){
NSLOG(@“当前组=%@”,组);
[组枚举AssetSungBlock:AssetUmerator];
}
否则{
//我们列举了所有的团体
}
};
assetsList=[[NSMutableArray alloc]init];
AlassetLibrary*库=[[[AlassetLibrary alloc]init]autorelease];
[库enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
故障块:^(N错误*错误){
NSLOG(@“故障:%@,[错误描述]);
}];
}
更新:问题似乎来自enumerateGroupsWithTypes:usingBlock:failureBlock:method。 在我调用它之前,我实际上处于一个单独的线程中,但在它通过之后,它将切换到主线程…

来自:

在iOS中,操作队列不使用Grand Central Dispatch来执行 行动它们为非并发操作创建单独的线程 并从当前线程启动并发操作。暂时 论并发与非并发的区别 操作及其执行方式,请参阅NSOperation类参考

因此,NSOperationQueue始终在以下位置的单独线程上执行:

在iOS中,操作队列不使用Grand Central Dispatch来执行 行动它们为非并发操作创建单独的线程 并从当前线程启动并发操作。暂时 论并发与非并发的区别 操作及其执行方式,请参阅NSOperation类参考


因此,NSOperationQueue总是在一个单独的线程上运行

是的,我知道,这就是为什么我不明白为什么它没有在ios 4.2.1设备上的单独线程上运行。我在nsoperation中添加了这段代码,如果([NSThread isMainThread]){NSLOG(@“isMainThread”);}并且由于图像处理,主线程在ios4上被完全锁定,而不是在ios5上,我可以在ios4上而不是在ios5上看到日志消息……这是不正确的-或者至少当您发布它时,文件已经过时了。在iOS 4及更高版本中,操作队列使用Grand Central Dispatch执行操作。在iOS 4之前,他们为非并发操作创建单独的线程,并从当前线程启动并发操作。是的,我知道这一点,这就是为什么我不理解为什么它没有在iOS 4.2.1设备上的单独线程上运行。我在nsoperation中添加了这段代码,如果([NSThread isMainThread]){NSLOG(@“isMainThread”);}并且由于图像处理,主线程在ios4上被完全锁定,而不是在ios5上,我可以在ios4上而不是在ios5上看到日志消息……这是不正确的-或者至少当您发布它时,文件已经过时了。在iOS 4及更高版本中,操作队列使用Grand Central Dispatch执行操作。在iOS 4之前,它们为非并发操作创建单独的线程,并从当前线程启动并发操作。你猜错了。请在创建队列的位置发布代码,并将操作添加到其中。好的,这是一些代码。基本上加载CurrentCameraroll扫描cameraRoll并将缩略图保存在本地目录中是否覆盖-isConcurrent?尝试在
main
方法中记录
[NSThread isMainThread]
的值,以确认它正在主线程上运行。是否可能有次线程正在启动,但在主线程上执行同步任务(例如UI更新)。好的,我尝试了,并确认它正在主线程上运行。您猜错了。请在创建队列的位置发布代码,并将操作添加到其中。好的,这是一些代码。基本上加载CurrentCameraroll扫描cameraRoll并将缩略图保存在本地目录中是否覆盖-isConcurrent?尝试在
main
方法中记录
[NSThread isMainThread]
的值,以确认它正在主线程上运行。是否可能有次线程正在启动,但正在主线程上执行同步任务(例如UI更新)。好的,我尝试过,并确认它正在主线程上运行