将 MPMediaItem 保存到 NSMutableDictionary 中
我正在尝试将 MPMediaItem 保存在 nsmutableDictionary 中。
实际上,我的目的是让用户选择他的歌曲,然后将其保存在应用程序中,然后只要他想要就可以播放。
我添加了这段代码,用于将 MPMediaItem 保存到 Dictionary 中
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.
I am trying to save the MPMediaItem in nsmutableDictionary..
Actually my purpose is to let the user select his songs and then have it saved in the app and then whenever he wants he can play.
i have added this code for saving the MPMediaItem to Dictionary
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
[dict setObject:mediaItemCollection.representativeItem forKey:@"name"];
and added it in a NSMutableArray and then that array into NSUserDefaults.
but when i try to do this i get this error:
[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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该保存 MPMediaItems(我什至不知道它们是否有与其关联的键控归档器和解归档器),而是保存唯一标识符(通过
MPMediaItemPropertyPecientID
属性键)与每个项目关联。查看这个密切相关问题的答案,您可能会找到一条到达目的地的路径想去。
You shouldn't be saving MPMediaItems (I don't even know if these have keyed archivers & unarchivers associated with them), but save the unique identifier (referred to via
MPMediaItemPropertyPesistentID
property keys) associated with each item.Check out the answers to this closely related question and you might find a path to get to where you want to go.
将其设置为 NSData 然后存储以获得您想要的内容。它存档。
Set it to NSData and then store it to get what you want. It archives.