2013-09-01 32 views
0

我想存储一些关于从iTunes资料库抓取的项目的信息,并想知道如何命名文件而不会产生任何问题,如覆盖或类似的名称等等......在我从媒体库中获取的媒体项目中有元数据,这可能是名称使用最好的。如果我使用MPMediaItemPropertyPersistentID,我相信不会有任何类似的名称,但值保证在同步/非同步/同步周期期间保持持续不变...有没有更好的方法来做到这一点?iOS:在iTunes库项目中存储持久性数据时选择文件名

MPMediaItemPropertyTitle 
The title (or name) of the media item. This property is unrelated to the MPMediaItemPropertyAlbumTitle property. Value is an NSString object. 

MPMediaItemPropertyPersistentID 
The persistent identifier for the media item. Value is an NSNumber object containing a uint64_t (unsigned long long). 
The value of the MPMediaItemPropertyPersistentID identifier persists across application launches and across syncs that do not change the sync status of the media item. The value is not guaranteed to persist across a sync/unsync/sync cycle. 

回答

1

以下是我为保存图像时如何创建唯一名称的示例,这将为您提供唯一的文件名。

- (void) writeImageFile:(NSData *) image 
{ 
    CFUUIDRef newUniqueID = CFUUIDCreate (kCFAllocatorDefault); 
    CFStringRef newUniqueIDString = CFUUIDCreateString (kCFAllocatorDefault, newUniqueID); 
    NSString *filePath = [self getUniqueFilePathFrom:newUniqueIDString]; 
    [image writeToFile:filePath atomically:YES]; 
    self.pathToFullSizeImage = filePath; 
    CFRelease(newUniqueIDString); 
    CFRelease(newUniqueID); 
} 

希望它可以帮助你。

相关问题