来自plist词典KEYS,iOS的UITableView

时间:2009-12-28 23:43:04

标签: ios nsarray key plist jailbreak

我试图在越狱的iPhone上的iTunes目录中获取自定义铃声的名称。我可以成功列出自定义铃声,但它们显示为HWYH1.m4r,这是iTunes重命名文件的内容,但我知道这是解密歌曲实际名称的方法。

    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(@"name: %@",[customRingtone objectAtIndex:indexPath.row]);
    cell.textLabel.text = [customRingtone objectAtIndex:indexPath.row];

dictionary 正在返回:

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

cell.textLabel.text 正在返回:name: (null)

1 个答案:

答案 0 :(得分:5)

NSMutableArray *customRingtone = [[dictionary objectForKey:@"Name"] objectAtIndex:indexPath.row];

那条线完全错了。你的dictionary对象实际上是一个NSDictionary,其键的值等于'YBRZ.m4r'。您正在请求名为“名称”的键的值,该键不存在。然后,使用返回的对象,您将向它发送一个方法,就好像它是NSArray一样,但它不是。然后你希望返回NSArray。再说一次,我认为没有。应该更像这样:

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

另请注意,我没有使用NSMutableDictionary。如果你不需要字典是可变的,你可能应该有一个可变字典。