方法没有从plist获得价值

时间:2013-01-04 09:59:41

标签: iphone ios5 theos

出于某种原因,我没有从我的plist那里得到价值,我不确定为什么这里是plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CachedColors</key>
    <dict>
        <key>com.Halfbrick.Fruit</key>
        <string>0.00000,0.00000,0.00000</string>
        <key>com.amazon.Amazon</key>
        <string>0.00000,0.00000,0.00000</string>
        <key>com.apple.AdSheetPhone</key>
        <string>0.00000,0.00000,0.00000</string>
        <key>com.apple.AppStore</key>
        <string>0.28824,0.37059,0.48235</string>
    <key>default</key>
    <true/>
    <key>gradient</key>
    <false/>
    <key>opaque</key>
    <true/>
    <key>showedMessage</key>
    <true/>
    <key>translucent</key>
    <true/>
</dict>
</plist>

我的方法是:

SBApplication *frontApp = [(SpringBoard*)[UIApplication sharedApplication] _accessibilityFrontMostApplication];
NSString *frontAppBundleID = [frontApp displayIdentifier];
NSDictionary *statusBarCachedColors = [NSDictionary dictionaryWithContentsOfFile:@"/var/mobile/Library/Preferences/cc.tweak.statuscolor.plist"];
NSString *colorString = (NSString*)[statusBarCachedColors objectForKey:frontAppBundleID];
NSArray *components = [colorString componentsSeparatedByString:@","];
UIColor *tintColor = [UIColor colorWithRed:[[components objectAtIndex:0] floatValue] green:[[components objectAtIndex:1] floatValue] blue:[[components objectAtIndex:2] floatValue] alpha:1];

应该发生什么,我的方法将获得当前应用程序的显示ID,然后从plist获取应用程序的值,然后拆分值字符串并从数组中生成UIColor。因此,如果我打开AppStore,它将搜索plist并返回“0.28824,0.37059,0.48235”并将其变为颜色,但它似乎没有返回任何内容,我已经测试了displayIdentifier,这是正确的显示正确的应用程序显示ID,我只是不知道它为什么没有获得值

3 个答案:

答案 0 :(得分:1)

您错过了 CachedColors 项目。

NSString *colorString = (NSString*)[[statusBarCachedColors objectForKey:@"CachedColors"] objectForKey:frontAppBundleID];

答案 1 :(得分:0)

使用这个波纹管代码可能有用..

从像plow那样的plist中获取价值......

NSString *path = [[NSBundle mainBundle] pathForResource:@"PlistFileName" ofType:@"plist"];
NSMutableArray  *arrPList = [NSMutableArray arrayWithContentsOfFile:path];

使用你的代码后尝试使用以下逻辑..

float clrRed = [[components objectAtIndex:0] floatValue];
float clrGreen = [[components objectAtIndex:1] floatValue];
float clrBlue = [[components objectAtIndex:2] floatValue];

UIColor *tintColor = [UIColor colorWithRed:clrRed green:clrGreen blue:clrBlue floatValue] alpha:1];

答案 2 :(得分:0)

NSString *path = [[NSBundle mainBundle] pathForResource:
                      @"<plist file name>" ofType:@"plist"];

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];

试试这个希望它会起作用。