2
我打算在不影响程序或主线程执行的情况下,将所有照片库图像URL添加到单独线程的NSMutableArray中。在单独线程上运行ALAssetLibrary块
我需要在应用程序背景上执行进程,而其他操作正在进行。
因此,我在代码以及我的View Controller类的ViewDidLoad函数中编写了下面的代码,代码如下:我的应用程序委托类“didFinishLaunchingWithOptions”。
但是,其他功能在ALAsset块正在执行时不工作。
但方法“crcGeneration”正在工作,不会干扰其他功能。正如在下面的代码中可以看到的,在获得所有照片库URL之后,我在同一个线程中调用了ALAsset块内部的方法“crcGeneration”。
任何人都可以告诉我一个很好的方法来解决这个问题吗?
OnViewDidLoad:
//Calling the getAllURLofPhotLibraryImages Function on a seperate Thread.
[NSThread detachNewThreadSelector:@selector(getAllURLofPhotLibraryImages) toTarget:self withObject:nil];
Function for Getting all image URL's of PhotoLibrary.
**-(void)getAllURLofPhotLibraryImages**
{
urlStoreArray = [[NSMutableArray alloc] init]; //global array
void (^assetEnumerator)(struct ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
{
if(result != NULL)
{
// Here storing the asset's image URL's in NSMutablearray urlStoreArr
NSURL *url = [[result defaultRepresentation] url];
[urlStoreArray addObject:url];
}
};
void (^assetGroupEnumerator)(struct ALAssetsGroup *, BOOL *) = ^(ALAssetsGroup *group, BOOL *stop)
{
if(group != nil)
{
[group enumerateAssetsUsingBlock:assetEnumerator];
}
else
{
**[self crcGeneration];** //Genearting CRC for PhotoLibrary Images using urlStoreArray after got all the Photo Library URL's .
}
};
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetGroupEnumerator failureBlock: ^(NSError *error) { NSLog(@"Failure");
}];
}