Mi sembra di avere un problema casuale che non ho idea del perché sta accadendo. Non riesco a ottenere che lo photoLibraryDidChange:(PHChange *)changeInstance
venga chiamato dall'osservatore. Ho realizzato diversi progetti vuoti e tutti stanno dimostrando questo problema, a volte l'osservatore delle modifiche viene richiamato durante l'installazione iniziale dell'app, ma non viene mai chiamato dopo l'esecuzione delle modifiche nell'app Foto. Ho anche resettato il simulatore senza alcun risultato. Apprezzerei qualsiasi aiuto offerto.PHPhotoLibrary change observer non chiamato
Codice:
#import <UIKit/UIKit.h>
#import <Photos/Photos.h>
@interface ViewController : UIViewController <PHPhotoLibraryChangeObserver>
@end
- (void)viewDidLoad
{
[super viewDidLoad];
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status)
{
if (status == PHAuthorizationStatusAuthorized)
{
[PHPhotoLibrary.sharedPhotoLibrary registerChangeObserver:self];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0),^
{
[self setup];
});
}
}];
}
- (void)setup
{
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc]init];
fetchOptions.wantsIncrementalChangeDetails = YES;
PHFetchResult *smartAlbumsFetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAny options:fetchOptions];
for (PHAssetCollection *sub in smartAlbumsFetchResult)
{
PHFetchResult *fetch = [PHAsset fetchAssetsInAssetCollection:sub options:fetchOptions];
}
}
- (void)photoLibraryDidChange:(PHChange *)changeInstance
{
NSLog(@"Not called");
}
- (void)dealloc
{
[PHPhotoLibrary.sharedPhotoLibrary unregisterChangeObserver:self];
}
Di cosa stai parlando. Vado all'app Foto e preferita, sfavorevole ed elimina le immagini di archivio. – klcjr89
Non segui? Non c'è codice. Questo sta manipolando nell'app Foto, che dovrebbe notificare modifiche. – klcjr89
@matt Sì, ho creato un progetto vuoto a vista singola con nulla in esso per cercare di capire perché non funziona ora. Non essendo scortese, stava lavorando per me negli ultimi giorni, ma non è ora. – klcjr89