更新时间:2022-10-30 12:36:46
好了,所以这里的交易,或者现在修复。它看起来像设置在播放器preFS一个可变数组是打破,但设置一个NSArray是没有的。
所以你的数组转换为一个可变的,添加对象,那么你的可变数组转换为一个NSArray,然后设置用户默认设置。
下面是一个例子....
* NSUserDefaults的preFS = [NSUserDefaults的standardUserDefaults]
NSArray的* ARR = preFS arrayForKey:@MyAgenda]; _MyAgenda = [NSMutableArray的arrayWithArray:ARR];
[_MyAgenda ADDOBJECT:的SessionID]; ARR = [NSArray的arrayWithArray:_MyAgenda]; [preFS的setObject:ARR forKey:@MyAgenda];
[preFS同步]。
Ok, so I launched an app last week before iOS8 came out. Everything was working fine in iOS7 and below. But now since people have updated to iOS8 my app is pausing/crashing for no reason.
I came to terms that it is when I set an NSMutableArray to the NSUserDefaults, it pauses.
Please note, the NSMutableArray is an array of NSStrings.
BUT (this is weird) if I breakpoint skip through the code it works and I get no pause.
Here is the function that it is blowing up...
-(void)UpdateMyAgenda:(NSString*)SessionID Remove:(BOOL)Remove{
if(!Remove){
//Do not Remove
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
_MyAgenda = [[NSMutableArray alloc]init];
_MyAgenda = [prefs mutableArrayValueForKey:@"MyAgenda"];
[_MyAgenda addObject:SessionID];
[prefs setObject:_MyAgenda forKey:@"MyAgenda"];
[prefs synchronize];
}else{
//Remove
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
_MyAgenda = [[NSMutableArray alloc]init];
_MyAgenda = [prefs mutableArrayValueForKey:@"MyAgenda"];
[_MyAgenda removeObject:SessionID];
[prefs setObject:_MyAgenda forKey:@"MyAgenda"];
[prefs synchronize];
}
for (NSString *item in _MyAgenda) {
NSLog(@"%@", item);
}
NSLog(@"-----------");
}
Ok so here is the deal, or a fix for now. It looks like setting a mutable array in the player prefs is breaking, but setting an NSArray is not.
So convert your array to a mutable one, add the object, then convert your mutable array to an nsarray and then set the user default.
Here is an example....
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSArray *arr = [prefs arrayForKey:@"MyAgenda"];
_MyAgenda = [NSMutableArray arrayWithArray:arr];
[_MyAgenda addObject:SessionID];
arr = [NSArray arrayWithArray:_MyAgenda];
[prefs setObject:arr forKey:@"MyAgenda"];
[prefs synchronize];