2015-05-05 20 views
5

kapsamındaki filtreler Fotoğraflar çerçevesini kullanıyorum (PhotoKit). Uygulamamda Anları topladım (PHAssetCollection türünde). PHAssetCollection, CLLocation *approximateLocation'un bir özelliğine sahiptir.Filtre PHAssetCLLocationCoordinate2d

Ancak, PhotoKit'ten Anları aldığımda çalışmak için NSPredicate'u alamıyorum.

-(void)getMomentsNearCoordinate:(CLLocationCoordinate2D)coordinate completionBlock:(PKAssetManagerArrayBlock)completionBlock{ 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     PHFetchOptions *options = [[PHFetchOptions alloc] init]; 
     options.predicate = [NSPredicate predicateWithFormat:@"approximateLocation.coordinate.latitude < 37.0"]; 

     self.moments = [PHAssetCollection fetchMomentsWithOptions:options]; 

     // Convert PHCollection into NSArray 
     NSMutableArray *momentsArray = [[NSMutableArray alloc]initWithCapacity:self.moments.count]; 
     [self.moments enumerateObjectsUsingBlock:^(PHAssetCollection *moment, NSUInteger idx, BOOL *stop) { 
      [momentsArray addObject:moment]; 
     }]; 

     dispatch_async(dispatch_get_main_queue(), ^{ 
      completionBlock([NSArray arrayWithArray:momentsArray]); 
     }); 
    }); 
} 

ayıklayıcı hata ile

self.moments = [PHAssetCollection fetchMomentsWithOptions:options]; 

üzerinde durur: Ben startDate veya endDate göre filtre uygulamak için NSPredicate kullanabilirsiniz beri

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported predicate in fetch options: approximateLocation.coordinate.latitude < 37'

Bu garip görünüyor.

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported predicate in fetch options: BLOCKPREDICATE(0x27d338)'

:

-(void)getMomentsNearCoordinate:(CLLocationCoordinate2D)coordinate completionBlock:(PKAssetManagerArrayBlock)completionBlock{ 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     PHFetchOptions *options = [[PHFetchOptions alloc] init]; 
     options.predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) { 
      // Logic goes here 
      return YES; 
     }]; 

     self.moments = [PHAssetCollection fetchMomentsWithOptions:options]; 

     // Convert PHCollection into NSArray 
     NSMutableArray *momentsArray = [[NSMutableArray alloc]initWithCapacity:self.moments.count]; 
     [self.moments enumerateObjectsUsingBlock:^(PHAssetCollection *moment, NSUInteger idx, BOOL *stop) { 
      [momentsArray addObject:moment]; 
     }]; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      completionBlock([NSArray arrayWithArray:momentsArray]); 
     }); 
    }); 
} 

Yine ayıklayıcı farklı bir hata mesajı ile

self.moments = [PHAssetCollection fetchMomentsWithOptions:options]; 

durur:

neyse, ertesi ben blokla NSPredicate denemek düşünce Sonunda, CloudKit documentation numaralı telefondan, fil için yeni bir destek eklediklerini okumayı hatırladım mesafeli tering. Ancak bu, NSPredicate değil CKQuery içindir. Her neyse denemeye karar verdim. Ben benim bir CLLocation sonra çağrı yapmak için koordinat kullanın:

-(void)getMomentsNearLocation:(CLLocation*)location completionBlock:(PKAssetManagerArrayBlock)completionBlock{ 
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
     PHFetchOptions *options = [[PHFetchOptions alloc] init]; 
     options.predicate = [NSPredicate predicateWithFormat:@"distanceToLocation:fromLocation:(%K,%@) < %f", 
          location, 
          2.0]; 

     self.moments = [PHAssetCollection fetchMomentsWithOptions:options]; 

     // Convert PHCollection into NSArray 
     NSMutableArray *momentsArray = [[NSMutableArray alloc]initWithCapacity:self.moments.count]; 
     [self.moments enumerateObjectsUsingBlock:^(PHAssetCollection *moment, NSUInteger idx, BOOL *stop) { 
      [momentsArray addObject:moment]; 
     }]; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      completionBlock([NSArray arrayWithArray:momentsArray]); 
     }); 
    }); 
} 

Bunu tahmin. Hata: Sadece PHAssetCollections listesinde yineleme ve elle CLLocation yakın ise hesaplarız arada

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CLLocation rangeOfString:]: unrecognized selector sent to instance 0x19e3e350' 

. Bu çok daha az verimli olacaktır. Eğer PHFetchOptions belgelerin Tablo 1'de bakarsak

+0

Bunu işe aldınız mı? –

+0

Hayır. Asıl gönderiden bu yana kodu fazla karıştırmam. Çalışırsanız lütfen geri gönderin. Belki iOS 10'da çalışır? – VaporwareWolf

cevap

0

, size sadece PHAssetCollections yüklemi filtreleme için aşağıdaki tuşları kullanabilirsiniz göreceksiniz:

SELF 
localIdentifier 
localizedTitle (or title) 
startDate 
endDate 
estimatedAssetCount 

Eğer aksine, (a PHCollection filtre uygulamak istiyorsanız bir PHAssetCollection), sonra aşağıdaki tuşları sınırlıdır:

SELF 
localIdentifier 
localizedTitle (or title) 
startDate 
endDate 

hiçbir şey andıran "approximateLocation" bir destek anahtarıdır. Ama bekleyin! localizedTitle genellikle bir yer adıdır. Aksi halde görmedim. Bu nedenle, filtreleme anı koleksiyonları tarafından filtrelenmiş anlar elde edebilirsiniz.