我正在尝试使用下面的代码将会话保存到NSUserDefaults,并且出于某种原因这样做会导致我的应用程序崩溃并出现以下错误。
2015-10-31 12:38:22.327 App [13930:4844726] ***终止app到期 未捕获的异常'NSInvalidArgumentException',原因:'尝试 插入非属性列表对象{type = immutable dict,count = 17,entries => 0: status = 1 1:theme = {contents =“”} 2:roles = {type = immutable dict,count = 2,entries => 0:2 = {contents =“authenticated user”} 1:3 = {contents =“administrator”}}
3:uid = 1 5:access = {contents =“1446319867”} 6:login = {value = +1446320300,type = kCFNumberSInt64Type} 7:picture = 9:{contents = “signature_format”} = 10:init = {contents = “brittany@email.ca”} 13:signature = {contents =“”} 14:data = {value = false} 15:language = {contents =“”} 16:created = {contents =“1428187324”} 17: {contents =“rdf_mapping”} = {type = immutable dict,count = 3,entries => 0: rdftype = {type = immutable,count = 1,values =(0:{contents =“sioc:UserAccount”})} 1:name = {type = immutable dict,count = 1,entries => 2: 谓词= {type = immutable, count = 1,values =(0:{contents =“foaf:name”})}}
2:主页= {type = immutable dict,count = 2,entries => 0:type = rel 2:谓词 = {type = immutable,count = 1,values =(0:{contents = “foaf:page”})}}
}
18:timezone = {contents = “America / Los_Angeles”} 21:name = admin 22:mail = {contents =“email@email.ca”}} 关键diosSession' ***首先抛出调用堆栈:(0x183db8f5c 0x1989aff80 0x183db8ea4 0x183df5970 0x183d427c0 0x183d416d8 0x183df5c74 0x183df520c 0x183df8a1c 0x184c21138 0x1000ef5c8 0x1000f14fc 0x100120850 0x1000e8248 0x10026dd70 0x10026dd30 0x100273780 0x183d70258 0x183d6e0c0 0x183c9cdc0 0x18edf0088 0x189376f44 0x100159674 0x1991da8b8)libc ++ abi.dylib:以未捕获的异常终止 输入NSException
知道为什么吗?
谢谢!
{{1}}
答案 0 :(得分:3)
“知道为什么吗?”是:
[[DIOSSession sharedSession] user]
我不知道NSArray
是什么,但只有NSDictionary
,NSString
,NSData
,NSNumber
,NSDate
和{ {1}}可以存储。
所以我想这就是原因。
答案 1 :(得分:0)
请尝试这个
用于设置对象:
NSData *yourData = [NSKeyedArchiver archivedDataWithRootObject:[[DIOSSession sharedSession] user]];
[[NSUserDefaults standardUserDefaults] setObject:yourData forKey:@"yourKey"];
[[NSUserDefaults standardUserDefaults] synchronize];
获取对象:
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"yourKey"];
DIOSSession *object = [NSKeyedUnarchiver unarchiveObjectWithData:data];