Hallo Leute,
ich habe mal wieder eine Frage zu multithreading.
Ich benutzte das Asset Library um mir die Photos zu holen, das in dieser Zeit nicht die UI Blockiert ist benutzte ich ein Operation Block.
So weit Funktioniert alles nur jetzt ist es extrem langsam und eigentlich funktioniert das Asset Library eh asynchron ich verstehe nicht warum die UI blockiert ist.
Ich habe wahrscheinlich irgendwas Falsch verstanden vielleicht könnt ihr mich aufklären.
Hier der Code.
Photo Engine:
Alles anzeigen
Methoden Aufruf:
Alles anzeigen
ich bedanke mich schon einmal im voraus für die Hilfe.
ich habe mal wieder eine Frage zu multithreading.
Ich benutzte das Asset Library um mir die Photos zu holen, das in dieser Zeit nicht die UI Blockiert ist benutzte ich ein Operation Block.
So weit Funktioniert alles nur jetzt ist es extrem langsam und eigentlich funktioniert das Asset Library eh asynchron ich verstehe nicht warum die UI blockiert ist.
Ich habe wahrscheinlich irgendwas Falsch verstanden vielleicht könnt ihr mich aufklären.
Hier der Code.
Photo Engine:
Quellcode
- #import "LCPhotoEngine.h"
- #import "NSDate+LCTimeShiftDate.h"
- @implementation LCPhotoEngine
- - (void)getAllPhotos
- {
- NSMutableArray *photos = [NSMutableArray new];
- ALAssetsLibrary *assetLibrary = [ALAssetsLibrary new];
- [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
- @autoreleasepool {
- if (group) { // #1
- [group setAssetsFilter:[ALAssetsFilter allPhotos]];
- [group enumerateAssetsUsingBlock: ^(ALAsset *asset, NSUInteger index, BOOL *stop) {
- if (!asset && (index == NSNotFound)) {
- // NotFound
- } else {
- [photos addObject:asset];
- if ([self.delegate respondsToSelector:@selector(photoEngine:didReturnWithAssetRepresentation:)]) {
- [self.delegate photoEngine:self didReturnWithAssetRepresentation:asset];
- }
- }
- }];
- } else { // #1
- if ([self.delegate respondsToSelector:@selector(photoEngine:didFinishWithResults:)]) {
- [self.delegate photoEngine:self didFinishWithResults:(NSArray*)photos];
- }
- } // #1 else
- } // autoreleasepool
- }
- // failureBlock
- failureBlock:^(NSError *error) {
- NSLog(@"error enumerating AssetLibrary groups %@\n", error);
- }];
- }
- - (NSArray*)filterValidPhotosInAssets:(NSArray*)assets byDateBlocks:(NSArray*)dates
- {
- __block NSMutableArray *validPhotos = [NSMutableArray new];
- [assets enumerateObjectsUsingBlock:^(ALAsset *asset, NSUInteger idx, BOOL *stop) {
- if([self isValidAsset:asset byDates:dates]) {
- [validPhotos addObject:[UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage]];
- }
- }];
- if(!validPhotos.count) {
- [validPhotos addObject:[UIImage imageNamed:@"dev_current_record_image@2x.png"]];
- }
- return validPhotos;
- }
- - (BOOL)isValidAsset:(ALAsset*)asset byDates:(NSArray*)dates
- {
- __block NSDate *creationDate = [NSDate dateTimeShiftWithDate:[asset valueForProperty:ALAssetPropertyDate]];
- __block BOOL isValid = NO;
- [dates enumerateObjectsUsingBlock:^(NSArray *periodOfTime, NSUInteger idx, BOOL *stop) {
- NSDate *startDate = periodOfTime.firstObject;
- NSDate *enddate = periodOfTime.lastObject;
- if([startDate compare:creationDate] == NSOrderedAscending &&
- [enddate compare:creationDate] == NSOrderedDescending
- ) {
- isValid = YES;
- }
- }];
- return isValid;
- }
- @end
Quellcode
ich bedanke mich schon einmal im voraus für die Hilfe.