-1

出于某种原因,我没有从我的 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,我只是不知道为什么它没有获得价值

4

3 回答 3

1

您错过了CachedColors项目。

NSString *colorString = (NSString*)[[statusBarCachedColors objectForKey:@"CachedColors"] objectForKey:frontAppBundleID];
于 2013-01-04T12:36:23.383 回答
0

使用下面的代码可能会起作用..

从 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];
于 2013-01-04T10:09:10.067 回答
0
NSString *path = [[NSBundle mainBundle] pathForResource:
                      @"<plist file name>" ofType:@"plist"];

NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];

试试这个希望它会工作。

于 2013-01-04T10:12:07.573 回答