I seem to be having a random problem that I have no idea why is happening. I cannot seem to get the photoLibraryDidChange:(PHChange *)changeInstance
to be called by the observer. I've made several blank projects and all are demonstrating this issue, the change observer will sometimes be called upon initial app installation, but is never called after when I perform changes in the Photos app. I've also reset the simulator to no avail. I'd appreciate any help offered.
Code:
#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];
}