objective c - Only first object of NSMutableArray is stored in NSUserDefaults -
i trying store queue of uilocalnotification solve limit problem. used this approach , archive , unarchive object first one.
how archive objects nsmutablearray?
code// init/unarchive queue if (self.queue == nil) { // seek loading stored array nsuserdefaults *currentdefaults = [nsuserdefaults standarduserdefaults]; nsdata *datarepresentingsavedarray = [currentdefaults objectforkey:@"localnotificationqueue"]; if (datarepresentingsavedarray != nil) { nsarray *oldsavedarray = [nskeyedunarchiver unarchiveobjectwithdata:datarepresentingsavedarray]; if (oldsavedarray != nil) { self.queue = [[nsmutablearray alloc] initwitharray:oldsavedarray]; } else { self.queue = [[nsmutablearray alloc] init]; } } else { self.queue = [[nsmutablearray alloc] init]; } } // add together [self.queue addobject:notif]; // store queue [[nsuserdefaults standarduserdefaults] setobject:[nskeyedarchiver archiveddatawithrootobject:self.queue] forkey:@"localnotificationqueue"];
if add together items 1,2,3. restart , load. have 3.
add 1,2,3. restart , load. have 3, 1, 2.
if matters. phonegap/cordova cdvplugin.
after
[[nsuserdefaults standarduserdefaults] setobject:[nskeyedarchiver archiveddatawithrootobject:self.queue] forkey:@"localnotificationqueue"];
you need phone call
[[nsuserdefaults standarduserdefaults] synchronize]
to save user defaults.
objective-c cordova archive
No comments:
Post a Comment