如何读取plist字典,并将键(而不是值)保存在另一个plist的数组字符串中?

时间:2016-05-12 22:20:50

标签: ios objective-c dictionary jailbreak theos

我正在设备中使用theos创建一个JB调整。

我想读一个像这样的plict dict:

ASNPrefs.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>ASNcenterEnabled</key>
            <false/>
            <key>ASNcornerEnabled</key>
            <false/>
            <key>ASNnoCenterEnabled</key>
            <false/>
            <key>ASNdepthSizeEnabled</key>
            <false/>
        </dict>
        </plist>

并将键作为数组只写入另一个plist:

ASNkeys.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>ASNkeys</key>
            <array>
                <string>ASNcenterEnabled</string>
                <string>ASNcornerEnabled</string>
                <string>ASNnoCenterEnabled</string>
                <string>ASNdepthSizeEnabled</string>
            </array>
        </dict>
    </plist>

我已经使用此操作创建了一个按钮,但没有任何反应:

- DEFINED AT BEGINNING OF .MM:


#define prefs @"/User/Library/Preferences/ASNPrefs.plist"
#define asnKeysPath @"/User/Documents/asnKeys.plist"
#define asnKeysDict [[NSDictionary dictionaryWithContentsOfFile:asnKeysPath] objectForKey:@"keys"]



- IN THE IMPLEMENTATION:


   -(void)ASNkeys {
        NSDictionary *asnPrefs = [NSDictionary dictionaryWithContentsOfFile:prefs];
        NSArray *allKeys = [prefs allKeys];

    [allKeys writeToFile:asnKeysDict atomically:YES];
        }

谢谢!

2 个答案:

答案 0 :(得分:0)

由于您的plist是词典,请使用dictionaryWithContentsOfFile:中的NSDictionary(而不是来自arrayWithContentsOfFile:的{​​{1}})。获得字典后,可以使用NSArray方法获取键的数组,然后将该数组写入plist。

HTH

答案 1 :(得分:0)

最后!!

经过大量的改变......谢谢你们所以马克思CRD !!

NSString  *arrayPath;
NSString  *dictPath;
NSString  *origPath;

// Get path to documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

            if ([paths count] > 0)  {

                origPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"com.maat.asnPrefs.plist"];

                NSDictionary *dictOrig = [NSDictionary dictionaryWithContentsOfFile:origPath];

                NSArray *ASNKeys = [dictOrig allKeys]; //ForObject:@"true"];

                NSDictionary *dictionary = @{@"ASNKeys" : allKeys};

                // Path to save array data
                arrayPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"array.out"];

                // Path to save dictionary
                dictPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"asnKeys.plist"];

                // Write array
                [asnKeys writeToFile:arrayPath atomically:YES];

                // Write dictionary
                [dictionary writeToFile:dictPath atomically:YES];
}