2013-09-01 40 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); 
} 

希望它可以幫助你。

相關問題