objective c - AssetsLibrary framework broken on iOS 8 -


i have run issue on ios 8 assets library framework appears bug in ios 8. if create album called 'mymedia' , delete it, when try create album again, chunk of code below returns 'nil' indicating album 'mymedia' exists though not because deleted using 'photos' app.

__block alassetsgroup *mygroup = nil; __block bool addassetdone = false; nsstring *albumname = @"mymedia"; [assetslib addassetsgroupalbumwithname:albumname                            resultblock:^(alassetsgroup *group) {                                mygroup = group;                                addassetdone = true;                            } failureblock:^(nserror *error) {                                nslog( @"failed create album: %@", albumname);                                addassetdone = true;                            }];  while (!addassetdone) {     [[nsrunloop currentrunloop] rununtildate:[nsdate datewithtimeintervalsincenow:0.05f]]; } return mygroup; // returns nil if group has been created , deleted 

this same method works when creating brand new album 'mymedia2.' has else experienced issue , know of workaround or solution? solution move new 'photos' framework or doing incorrect here? note code works on ios7.x

actually steps reproduce problem follows -> 1. uninstall app takes photos , saves them custom album 2. under ios photos delete custom album has saved photos in 3. install app 4. if take pictures or record videos app not create them or store them. if under ios photos albums custom album 1 not exist , none of pictures/videos taken app exist.

my previous answer incorrect. had not tested out. did figure out had done , difficult got work. had app run on both ios 7.x.x , ios 8.x.x , create custom album had been deleted app -->

  1. i wrote 2 chunks of code: 1 uses photos framework on ios 8.x.x , 1 uses assetslibrary framework on ios 7.x.x

  2. sp app run on both ios versions, linked app photos framework changed required optional not loaded on ios 7.x.x

  3. because photos framework code not called directly @ runtime on ios 7.x.x, had change loaded classes, functions (and blocks!) dynamically @ runtime

here code chunk works when running on iphone. should work in simulator -->

// phphotolibrary_class non-nil on ios 8.x.x class phphotolibrary_class = nsclassfromstring(@"phphotolibrary");  if (phphotolibrary_class) {     /**     *     ios 8..x. . code has called dynamically @ runtime , not link on ios 7.x.x ...      [[phphotolibrary sharedphotolibrary] performchanges:^{         [phassetcollectionchangerequest creationrequestforassetcollectionwithtitle:title];     } completionhandler:^(bool success, nserror *error) {         if (!success) {             nslog(@"error creating album: %@", error);         }     }];     */      // dynamic runtime code code chunk listed above                 id sharedphotolibrary = [phphotolibrary_class performselector:nsselectorfromstring(@"sharedphotolibrary")];      sel performchanges = nsselectorfromstring(@"performchanges:completionhandler:");      nsmethodsignature *methodsig = [sharedphotolibrary methodsignatureforselector:performchanges];      nsinvocation* inv = [nsinvocation invocationwithmethodsignature:methodsig];     [inv settarget:sharedphotolibrary];     [inv setselector:performchanges];      void(^firstblock)() = ^void() {         class phassetcollectionchangerequest_class = nsclassfromstring(@"phassetcollectionchangerequest");         sel creationrequestforassetcollectionwithtitle = nsselectorfromstring(@"creationrequestforassetcollectionwithtitle:");         [phassetcollectionchangerequest_class performselector:creationrequestforassetcollectionwithtitle withobject:albumname];      };      void (^secondblock)(bool success, nserror *error) = ^void(bool success, nserror *error) {        if (success) {            [assetslib enumerategroupswithtypes:alassetsgroupalbum usingblock:^(alassetsgroup *group, bool *stop) {                if (group) {                    nsstring *name = [group valueforproperty:alassetsgrouppropertyname];                    if ([albumname isequaltostring:name]) {                        groupfound = true;                        handler(group, nil);                    }                }            } failureblock:^(nserror *error) {                handler(nil, error);            }];        }         if (error) {            nslog(@"error creating album: %@", error);            handler(nil, error);        }    };     // set success , failure blocks.    [inv setargument:&firstblock atindex:2];    [inv setargument:&secondblock atindex:3];     [inv invoke];  } else {       // code creates album on ios 7.x.x fails    // in situations such if album has been deleted    // on ios 8...x. .                  [assetslib addassetsgroupalbumwithname:albumname        resultblock:^(alassetsgroup *group) {        handler(group, nil);    } failureblock:^(nserror *error) {        nslog( @"failed create album: %@", albumname);        handler(nil, error);    }]; } 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -