views:

699

answers:

1

I am attempting to get the name of the custom ringtones in the itunes directory on the iPhone. I can successfully list the custom ringtones, but they re displayed as HWYH1.m4r, which is what iTunes renames the file, but I know theres a way to decipher the actualy name of the song, for example: UHHEN2.m4r = TheSongName.

    NSMutableDictionary *custDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/iPhoneOS/private/var/mobile/Media/iTunes_Control/iTunes/Ringtones.plist"];
    NSMutableDictionary *dictionary = [custDict objectForKey:@"Ringtones"];
    NSMutableArray *customRingtone = [[dictionary objectForKey:@"Name"] objectAtIndex:indexPath.row];
    //NSLog(@"dictionary: %@",dictionary);
    NSLog(@"name: %@",[customRingtone objectAtIndex:indexPath.row]);
    cell.textLabel.text = [customRingtone objectAtIndex:indexPath.row];

dictionary is returning:

"YBRZ.m4r" =     
{
    GUID = 17A52A505A42D076;
    Name = "Wild West";
    "Total Time" = 5037;
};

cell text is returning:

 name: (null)
+3  A: 
NSMutableArray *customRingtone = [[dictionary objectForKey:@"Name"] objectAtIndex:indexPath.row];

That line is totally wrong. Your dictionary object it, in fact, an NSDictionary with keys equal to values like 'YBRZ.m4r'. You are requesting a value for a key named 'Name', which doesn't exist. Then, with that returned object, you are sending it a method as if it were an NSArray, which it isn't. And then you expect that to return an NSArray. Again, I don't think it does. It should be more like this:

NSArray *keys = [dictionary allKeys];
id key = [keys objectAtIndex:indexPath.row];
NSDictionary *customRingtone = [dictionary objectForKey:key];
NSString *name = [customRingtone objectForKey:@"Name"];
cell.textLabel.text = name;

Also note, I'm not using NSMutableDictionarys. If you don't need the dictionary to be mutable, you probably should have a mutable dictionary.

Ed Marty
awesome, many thanks!!
AWright4911