Save MPMediaItem to NSMutableDictionary

I am trying to save MPMediaItem in nsmutableDictionary ..

Actually my goal is to let the user select his songs, and then save it in the application, and then whenever he wants him to play.

I added this code to save MPMediaItem into the dictionary

NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; [dict setObject:mediaItemCollection.representativeItem forKey:@"name"]; 

and added it to NSMutableArray, and then this array to 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. 
+4
source share
2 answers

You don’t have to save the MPMediaItems (I don’t even know if the archivers and unarchivers associated with them are associated), but keep the unique identifier (referenced by MPMediaItemPropertyPesistentID ) associated with each element.

Browse through the answers to this close question and you can find a way to where you want to go.

+4
source

Set it to NSData, and then save it to get what you want. He is archiving.

+1
source

Source: https://habr.com/ru/post/1387868/


All Articles