我正在尝试将MPMediaItem保存在nsmutableDictionary ..
中其实我的目的是让用户选择他的歌曲,然后将其保存在应用程序中,然后只要他想要他就可以玩。
我已添加此代码以将MPMediaItem保存为字典
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:mediaItemCollection.representativeItem forKey:@"name"];
并将其添加到NSMutableArray中,然后将该数组添加到NSUserDefaults中。
但是当我尝试这样做时,我得到了这个错误:
[NSUserDefaults setObject:forKey:]:
Attempt to insert non-property value '(
{
desc = Test;
group = Main;
msg = Test;
name = test;
rec = (
{
name = "<MPConcreteMediaItem: 0x12b040> 8240103918041924793";
number = test;
}
);
type = "Play File";
}
)' of class '__NSArrayM'. Note that dictionaries and arrays in property lists must also contain only property values.
答案 0 :(得分:4)
你不应该保存MPMediaItems(我甚至不知道它们是否具有与它们相关联的密钥存档器和解析器),而是保存与每个相关联的唯一标识符(通过MPMediaItemPropertyPesistentID
属性键引用)项目
查看answers to this closely related question,您可能会找到一条前往目的地的路径。
答案 1 :(得分:1)
将其设置为NSData,然后将其存储以获得所需内容。它存档。