2012-05-03 158 views
-2

我有音乐应用程序的某些艺术家,它包含不同的专辑,用户可以购买每张专辑单独购买某个专辑时,其按钮从购买改为播放,并且这张专辑的歌曲将是在应用程序中列出,但当我做了一个更新的版本,我发现当用户更新他的应用程序时,它会像默认一样重置,播放按钮将被购买按钮取代,用户必须重新下载他已经在第一个版本购买的专辑,我怎样才能让所有的内容适用于所有版本,保持购买内容,同时更新

这就是如何按钮从“买进”调降至“玩”,在表中VIEW3改变其形象

NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *myPath = [myPathList objectAtIndex:0]; 
NSString* storagePath = [myPath stringByAppendingPathComponent:@"purchasedAlbums.plist"]; 
NSArray* valueList = [[NSArray alloc] initWithContentsOfFile:storagePath]; 

UIImage *change1 = [UIImage imageNamed:@"playalbum-06.png"]; 
UIImage *change2 = [UIImage imageNamed:@"playalbum-07.png"]; 
UIImage *change3 = [UIImage imageNamed:@"playalbum-08.png"]; 
UIImage *change4 = [UIImage imageNamed:@"playalbum-09.png"]; 
UIImage *change5 = [UIImage imageNamed:@"playalbum-11.png"]; 
UIImage *change6 = [UIImage imageNamed:@"playalbum-12.png"]; 
UIImage *change7 = [UIImage imageNamed:@"playalbum-10.png"]; 
UIImage *change8 = [UIImage imageNamed:@"playalbum-13.png"]; 
UIImage *change9 = [UIImage imageNamed:@"ipadplay-16.png"]; 
UIImage *change10 = [UIImage imageNamed:@"ipadplay-17.png"]; 
UIImage *change11 = [UIImage imageNamed:@"ipadplay-18.png"]; 
UIImage *change12 = [UIImage imageNamed:@"ipadplay-19.png"]; 
UIImage *change13 = [UIImage imageNamed:@"ipadplay-20.png"]; 
UIImage *change14 = [UIImage imageNamed:@"ipadplay-21.png"]; 

int i; 
for (i = 0; i < [AlbumsImages count]; i++) { 


if ([[valueList objectAtIndex:i+1] intValue]) { 
    if (i == 0) { 
     [AlbumsImages replaceObjectAtIndex:0 withObject:change1]; 
    } 
    if (i == 1) { 
     [AlbumsImages replaceObjectAtIndex:1 withObject:change2]; 
    } 
    if (i == 2) { 
     [AlbumsImages replaceObjectAtIndex:2 withObject:change3]; 
    } 
    if (i == 3) { 
     [AlbumsImages replaceObjectAtIndex:3 withObject:change4]; 
    } 
    if (i == 4) { 
     [AlbumsImages replaceObjectAtIndex:4 withObject:change5]; 
    } 
    if (i == 5) { 
     [AlbumsImages replaceObjectAtIndex:5 withObject:change6]; 
    } 
    if (i == 6) { 
     [AlbumsImages replaceObjectAtIndex:6 withObject:change7]; 
    } 
    if (i == 7) { 
     [AlbumsImages replaceObjectAtIndex:7 withObject:change8]; 
    } 
    if (i == 8) { 
     [AlbumsImages replaceObjectAtIndex:8 withObject:change9]; 
    } 
    if (i == 9) { 
     [AlbumsImages replaceObjectAtIndex:9 withObject:change10]; 
    } 
    if (i == 10) { 
     [AlbumsImages replaceObjectAtIndex:10 withObject:change11]; 
    } 
    if (i == 11) { 
     [AlbumsImages replaceObjectAtIndex:11 withObject:change12]; 
    } 
    if (i == 12) { 
     [AlbumsImages replaceObjectAtIndex:12 withObject:change13]; 
    } 
    if (i == 13) { 
     [AlbumsImages replaceObjectAtIndex:13 withObject:change14]; 
    } 

而这就是其中的专辑下载

request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:URL]]; 
       [request setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Caches"] 
                stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp3",[self FileNameGetter:Albumid FileID:CurrentSongID ]]]]; 

时保存,这就是当应用程序做负载

NSArray *myPathList = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); 
NSString *myPath = [myPathList objectAtIndex:0]; 
NSString* storagePath = [myPath stringByAppendingPathComponent:@"purchasedAlbums.plist"]; 
NSArray* valueList = [[NSArray alloc] initWithContentsOfFile:storagePath]; 
if ([valueList count]==0) { 
    valueList = [NSArray arrayWithObjects: @"0" ,@"0" ,@"0" , @"0" ,@"0" ,@"0" , @"0" ,@"0" ,@"0" , @"0" ,@"0" ,@"0" , @"0" ,@"0" ,@"0" , nil]; 
    [valueList writeToFile:storagePath atomically:true]; 
} 
valueList=nil; 
myPathList=nil; 
myPath =nil; 
storagePath =nil; 
[valueList release]; 
[myPathList release]; 
[myPath release]; 
[storagePath release]; 

发生什么事我真的很感谢所有帮助:)

回答

1

首先,如果你只想通过更新保留内容,将其保存在DocumentsDirectory而不是Caches中。可以使用restoreTransactions

+0

我以前将它们保存在DocumentsDirectory中,但Apple拒绝了该应用程序,因此我将它们保存在缓存中, –

+0

为这些文件添加** dontBackUp **标志,因此它们将不会与iCloud同步 –

+0

哥们可以为文档目录设置'dontbackup'吗?以及如何检查文件目录中的文件是否标记为'dontbackup'? –