objective c - iOS 10 with XCode 8 GM caused NSUserDefaults to intermittently not work -


note: have seen many other posts on stack overflow nsuserdefaults being renamed userdefaults in swift or not working on simulator until restart. not duplicate anyway. many of questions tagging against 4 years ago. question specific ios 10 year has worked in older versions. have mentioned in question question not duplicate of questions simulator bugs in swift , issue on device objective c bug. please read questions before marking duplicate

my issue different able reproduce on objective c , on physical device itself.

i created brand new project scratch test. placed code in viewdidload of view controller:

if (![[nsuserdefaults standarduserdefaults] valueforkey:@"checkifinitialized"]){     nslog(@"setting checkifinitialized not exist");     [[nsuserdefaults standarduserdefaults] setvalue:@"test" forkey:@"checkifinitialized"];     [[nsuserdefaults standarduserdefaults] synchronize];     self.view.backgroundcolor=[uicolor redcolor];     self.mylabel.text=@"nsuserdefaults not there, try running again"; } else {     nslog(@"checkifinitialized exists already");     self.view.backgroundcolor=[uicolor bluecolor];     self.mylabel.text=@"nsuserdefaults there time, try running again"; } 

now if run app 10 times, few times finds checkifinitialized , doesn't. no exact number on how many times fails might work 3 times fail next 2 times work 4 times , fail once , on.

now have noticed (not 100% sure though) issue seems happen when testing connected via xcode. if run launching app clicking app icon on device without xcode, seems work fine can't 100% sure.

i noticed error occur sometimes:

[user defaults] failed write value key checkifinitialized in cfprefsplistsource<0x1700f7200> (domain: com.xxxx.appname, user: kcfpreferencescurrentuser, byhost: no, container: (null)): path not accessible, switching read-only 

i have simple project on dropbox if want test out. suggest testing 10-15 times reproduce issue.

https://www.dropbox.com/s/j7vbgl6e15s57ix/nsuserdefaultbug.zip?dl=0

this works fine on ios 9 ios 10.

edit bug logged: 28287988

response apple dts team:

first off, should first determine whether standarduserdefaults or valueforkey failing. guess “standarduserdefaults” returning null and, if that’s case, that’s should guarding against generally. notably, standarduserdefaults return null if preference file encrypted in environment app running in (for example, preferences set “nsfileprotectioncomplete” , app running in background). shouldn’t issue standard foreground-only apps, it’s aware of anyway.

it’s xcode inducing problem here. xcode vastly complicates app launching environment in way that’s different standard app launch. guess being triggered xcode’s timing inducing an expected situation during app launch, if want more formal test of try setting single breakpoint in applicationdidfinishlaunching , continuing in debugger hit it. guess adding disrupts timing enough stop problem happening. sort of. it’s ios 10 in sense ios 9 never print log message, that’s because log message added in ios 10. code similar enough ios 9.3 suspect same behavior (at least in theory) possible in ios 9.

yes, reproducible bug.

  • it happens gm release of xcode 8 , ios 10.
  • it not linked question referring swift.
  • it not linked question referring beta versions of simulator.

the bug happens on devices , on simulator. intermittent: saving work 6 times , fail. unlike you, did not "failed write key" message.

the bug occurs when operating directly on device without xcode. in fact how discovered it.

you should report bug apple, since have short program reproduce it. same.

one key difference: in case failure in writing default. written value remains in nsuserdefaults. 1 key written while unchanged.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -