ios - NSKeyedArchiver Issue when app downloaded from iTunes via TestFlight -


i have strange bug i've bee trying track down several days. i'm saving state data game in file in app's documents directory.

everything had been working fine until recent ios update (not sure when, somewhere around 9.0). suddenly, data not being archive / unarchived correctly.

the weird part code works fine when run xcode ipad tethered mac or when in emulator. when download app itunes using testflight, no longer works. has made extremely difficult debug.

i've checked , double checked everything, i'm using url path, added error trapping code, etc. archiving fails work correctly when app installed itunes via testflight.

as last resort added new code archives object, unarchives variable, display data in label. resulting object contains null data.

no exceptions thrown.

just reiterate, code doesn't work when app in installed itunes.

here code snippet;

nsstring *documentdirectory = [[[[nsfilemanager defaultmanager] urlsfordirectory:nsdocumentdirectory indomains:nsuserdomainmask] lastobject] path];     nsstring* filepath =  [documentdirectory stringbyappendingpathcomponent:@"playertest.data"];     lbyplayerdata* pd1 = [[lbyplayerdata alloc ]init];     pd1.currentcountryid = 1;     pd1.lsn = @"123.456";     bool success = [nskeyedarchiver archiverootobject:pd1 tofile:filepath];     nsassert(success, @"archiverootobject failed");     lbyplayerdata* pd2 = nil;     @try {         pd2 = [nskeyedunarchiver unarchiveobjectwithfile:filepath];     } @catch (nsexception *exception) {         playerdatalabel.text = [nsstring stringwithformat:@"%@",exception.name];         playerundodatalabel.text = [nsstring stringwithformat:@"%@",exception.description];     } @finally {         nsassert((pd2 != nil), @"archiveplayerdataundo failed unarchive");         playerdatalabel.text = [nsstring stringwithformat:@"path: %@",filepath];         playerundodatalabel.text = [nsstring stringwithformat:@"undo country:%li lsn:%@",(long)pd2.currentcountryid,pd2.lsn];     } 

here data model

// //  lbyplayerdata.h  #import <foundation/foundation.h>  @interface lbyplayerdata : nsobject  @property (nonatomic,readonly) bool isnewgame; @property (nonatomic) nsinteger playerid; @property (nonatomic) nsinteger uscardidx; @property (nonatomic) nsinteger drawdeckidx; @property (nonatomic) nsinteger discarddeckidx; @property (nonatomic) nsinteger removedeckidx; @property (nonatomic) nsinteger currentcountryid; @property (nonatomic) nsstring* lsn; @property (nonatomic) nsstring* build;  @end  // //  lbyplayerdata.m  #import "lbyplayerdata.h"  @implementation lbyplayerdata  -(id)init {     self = [super init];     _isnewgame = yes;     return self; }  -(void)encodewithcoder:(nscoder *)acoder  { //    nslog(@"saving player data");     _isnewgame = no;     [acoder encodebool:_isnewgame         forkey: nsstringfromselector(@selector(isnewgame))];     [acoder encodeint64:_playerid         forkey: nsstringfromselector(@selector(playerid))];     [acoder encodeint64:_uscardidx        forkey: nsstringfromselector(@selector(uscardidx))];     [acoder encodeint64:_drawdeckidx      forkey: nsstringfromselector(@selector(drawdeckidx))];     [acoder encodeint64:_discarddeckidx   forkey: nsstringfromselector(@selector(discarddeckidx))];     [acoder encodeint64:_removedeckidx    forkey: nsstringfromselector(@selector(removedeckidx))];     [acoder encodeint64:_currentcountryid forkey: nsstringfromselector(@selector(currentcountryid))];     [acoder encodeobject:_lsn             forkey: nsstringfromselector(@selector(lsn))];     [acoder encodeobject:_build           forkey: nsstringfromselector(@selector(build))]; //    nslog(@"current counry: %li",(long)_currentcountryid); }  -(id)initwithcoder:(nscoder *)adecoder { //    nslog(@"loading player data");     self = [self init];     if (self) {         _isnewgame               =[adecoder decodeboolforkey:nsstringfromselector(@selector(isnewgame))];         [self setplayerid        :[adecoder decodeintegerforkey:nsstringfromselector(@selector(playerid))]];         [self setuscardidx       :[adecoder decodeintegerforkey:nsstringfromselector(@selector(uscardidx))]];         [self setdrawdeckidx     :[adecoder decodeintegerforkey:nsstringfromselector(@selector(drawdeckidx))]];         [self setdiscarddeckidx  :[adecoder decodeintegerforkey:nsstringfromselector(@selector(discarddeckidx))]];         [self setremovedeckidx   :[adecoder decodeintegerforkey:nsstringfromselector(@selector(removedeckidx))]];         [self setcurrentcountryid:[adecoder decodeintegerforkey:nsstringfromselector(@selector(currentcountryid))]];         [self setlsn             :[adecoder decodeobjectforkey :nsstringfromselector(@selector(lsn))]];         [self setbuild           :[adecoder decodeobjectforkey :nsstringfromselector(@selector(build))]];    }     return self; }  @end 

the problem nsassert. found code calling function archive object within nsassert statement.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -