我有某个艺术家的音乐应用程序,它包含不同的专辑,用户可以单独购买每张专辑,当购买某些专辑时,其按钮从购买变为播放,并且该专辑的歌曲将在应用程序中列出,但是当我做了一个更新的版本,我发现当用户更新他的应用程序时,它会像默认一样重置,播放按钮将被购买按钮取代,用户必须重新下载他已经购买的专辑版本,我怎样才能保持所有版本中的所有内容,
这就是按钮如何在表格视图中将其图像从“购买”更改为“播放”3
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];
我真的很感激任何帮助:)