问题描述
如何使用NSUserDefaults保留MPMediaItemCollection对象? MPMediaItemCollection对象是从iPod中选择的一首歌曲。
How do you persist a MPMediaItemCollection object using NSUserDefaults? The MPMediaItemCollection object is a single song selected from the iPod.
我一直在努力奋斗数小时!任何人对NSUserDefaults有任何想法或替代方案,或者从MPMediaItemCollection或其他任何东西转换?!
I have been struggling with this for hours! Anyone have any ideas or alternatives to NSUserDefaults or a conversion from MPMediaItemCollection, or anything?!
谢谢......
推荐答案
首先将MPMediaItemCollection转换/编码为NSData对象,然后使用NSUserDefaults将其存储起来:
First convert/encode the MPMediaItemCollection to an NSData Object and store it using NSUserDefaults using:
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:mediaItemCollection];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:data forKey:@"someKey"];
[defaults synchronize];
从那里,您可以解码并使用应用中的任何其他地方....
From there, you can decode and use anywhere else in your app....
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *data = [defaults objectForKey:@"someKey"];
MPMediaItemCollection *mediaItemCollection = [NSKeyedUnarchiver unarchiveObjectWithData:data];
这篇关于使用NSUserDefaults保留MPMediaItemCollection对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!