Hallo,
ik ben een simpel programma aan het schrijven naar aanleiding van
deze tutorial (het is eigenlijk voor Mac OSX, niet voor iPhone maar ik nam aan dat op dit forum de kennis ook in huis is) .
De gebruiker ziet een lijstje, kan daar een muziekbestand aan toevoegen en afspelen, en als het programma opnieuw wordt gestart staan de toegevoegde tracks er nog steeds in. Een soort uitgeklede versie (zeg maar naakt) van iTunes dus.
Het probleem is dat de toegevoegde tracks niet worden opgeslagen.
Ik gebruik een NSList om de bestandsnamen te weergeven die in Songs.plist staan. Dat werkt. Een bestand toevoegen aan de lijst werkt ook, het pad naar dat bestand komt dan in de lijst te staan. Echter als ik het programma afsluit en weer opstart, zijn de toegevoegde bestanden niet opgeslagen, ze worden niet weggeschreven. Alle stappen daarvoor werken prima, echt alleen het regeltje dat de bestanden opslaat werkt niet.
Relevante code:
Code:
- (IBAction)addSong:(id)sender {
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
// Enable the selection of directories in the dialog.
[openDlg setCanChooseDirectories:NO];
// Display the dialog. If the OK button was pressed, process the first file.
if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
{
// Get an array containing the full filenames of all files and directories selected.
NSArray* files = [openDlg URLs];
NSString* fileName = [files objectAtIndex:0];
//create a new song entry based on the input values
NSDictionary *dict = [NSDictionary dictionaryWithObject:fileName forKey:@"fileName"];
NSLog(@"dict = %@", dict);
//add it to the arrayController
[IBSongsArray addObject:dict];
}
//save the changes to the plist
if( ![[NSFileManager defaultManager] fileExistsAtPath:filePath] || [[NSFileManager defaultManager] isWritableFileAtPath:filePath]) {
NSLog(@"filepath: %@", filePath);
[[IBSongsArray arrangedObjects] writeToFile:filePath atomically:YES];
}
}
De NSLogs loggen wat ze moeten loggen.
Alvast dank,
Ruben