Hi Guys,
There is issue on upgrade of iOS 9 to iOS 10, NSUserDefaults(in Objective-C) or UserDefaults(in Swift) getting empty, Because of that App forcefully back to first screen of the app. (happing with whatsapp , facebook ), Its iOS issues.
But the time Apple solve the bug on next version of iOS, mean the while there is hot fix solution for this issues.
This issue is happing because of NSUserDefaults getting empty, So we need sure that, It shouldn't be empty, here I am store the NSUserDefaults dictionary into serialize file while going into background mode the app.
//Getting dictionary from NSUserDefaults
NSDictionary *defaultsDictionary = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
// Storing the dictionary into serialize file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent: @"myFile.ser"];
[NSKeyedArchiver archiveRootObject: defaultsDictionary toFile:filePath];
// Retrieving the Dictionary from serialize file
NSDictionary *restoreDictionary = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
Once you Get the Stored dictionary from the serialize file, afterthat check whether NSUserDefaults getting empty or not, if its empty than put this code
NSDictionary *restoreDictionary = [NSKeyedUnarchiver unarchiveObjectWithFile:filePath];
// here we are filling the NSUserDefaults once again....
for (id key in restoreDictionary) {
[[NSUserDefaults standardUserDefaults]removeObjectForKey:key];
[[NSUserDefaults standardUserDefaults]; objectForKey:keyName];
}
[[NSUserDefaults standardUserDefaults]
synchronize];
this way I have solved my issues... for hot fix... Once Apple will resolve this issue.. I'll remove that fix...
Hope you guys that will you.... If something is missing please let me know...!!!!
Thanks,
Indra Patel
Mumbai


No comments:
Post a Comment