xcode - What is the correct way to see if the current group has been removed with ALAssetsLibraryChangedNotification? -
when group has been removed –groupforurl:resultblock:failureblock:
not able find group anymore. might must compare nsurl received notification nsurl when using alassetsgrouppropertyurl
on current group. when current group has filter on it, nsurl appended &filter=
, nsurls won't match.
so if have current group of type alassetsgroup
, receive notification alassetslibrarychangednotification
. how check if current group 1 got removed?
my code far:
- (void)viewdidload { [super viewdidload]; self.collectionview.alwaysbouncevertical = yes; self.collectionview.backgroundcolor = [uicolor whitecolor]; self.collectionview.opaque = yes; self.collectionview.contentinset = uiedgeinsetsmake(9, 0, 0, 0); [self.collectionview registerclass:[cmphotocollectionviewcell class] forcellwithreuseidentifier:@"photocell"]; } - (void)viewwillappear:(bool)animated { [super viewwillappear:animated]; [[nsnotificationcenter defaultcenter] addobserver:self selector:@selector(assetslibrarydidchange:) name:alassetslibrarychangednotification object:nil]; self.title = [self.album.group valueforproperty:alassetsgrouppropertyname]; if (!self.assets) _assets = [nsmutablearray new]; else [self.assets removeallobjects]; alassetsgroupenumerationresultsblock assetsenumerationblock = ^(alasset *result, nsuinteger index, bool *stop) { if (result) [self.assets addobject:result]; }; [self.album.group enumerateassetsusingblock:assetsenumerationblock]; } - (void)viewwilldisappear:(bool)animated { [super viewwilldisappear:animated]; [[nsnotificationcenter defaultcenter] removeobserver:self]; } - (void)viewdidappear:(bool)animated { [super viewdidappear:animated]; [self.collectionview reloaddata]; } #pragma mark - #pragma mark assets library - (void)assetslibrarydidchange:(nsnotification *)notification { if (notification.userinfo[alassetlibrarydeletedassetgroupskey]) { nslog (@"album removed: %@", notification.userinfo[alassetlibrarydeletedassetgroupskey]); nslog (@"this album: %@", self.album.group); nslog (@"%@", [self.album.group valueforproperty:alassetsgrouppropertyurl]); // nsset nsurls of groups have been removed. // nsurl seems without filter, if current item // has filter on it, urls don't match. } } #pragma mark - uicollectionviewdelegate - (nsinteger)collectionview:(uicollectionview *)view numberofitemsinsection:(nsinteger)section { return self.assets.count; } - (uicollectionviewcell *)collectionview:(uicollectionview *)collectionview cellforitematindexpath:(nsindexpath *)indexpath { cmphotocollectionviewcell *cell = [collectionview dequeuereusablecellwithreuseidentifier:@"photocell" forindexpath:indexpath]; alasset *asset = self.assets[indexpath.row]; uiimage *thumbnail = [uiimage imagewithcgimage:asset.thumbnail]; cell.imageview.image = thumbnail; return cell; }
Comments
Post a Comment