I seem to have a random problem that I have no idea why this is happening. I can't seem to get photoLibraryDidChange:(PHChange *)changeInstance call an observer. I made several empty projects, and they all demonstrate this problem, the change observer will sometimes need to start the initial installation of the application, but it is never called after I make changes to the Photos application. I also had a reset simulator to no avail. I would 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]; }
source share