将 MPMediaItem 保存到 NSMutableDictionary 中

发布于 2024-12-23 05:43:09 字数 948 浏览 0 评论 0原文

我正在尝试将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

说谎友 2024-12-30 05:43:09

您不应该保存 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.

傲影 2024-12-30 05:43:09

将其设置为 NSData 然后存储以获得您想要的内容。它存档。

Set it to NSData and then store it to get what you want. It archives.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文