如何读取 plist 字典,并将键(而不是值)保存在另一个 plist 的数组字符串中?
How to read a plist dictionary, and save the keys (not the values) in array strings of another plist?
我正在我的设备中使用 theos 创建 JB 调整。
我想读一个像这样的 plist 字典:
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];
}
谢谢!
因为你的 plist 是一个 字典 使用 NSDictionary
中的 dictionaryWithContentsOfFile:
(而不是 NSArray
中的 arrayWithContentsOfFile:
)。有了字典后,您可以使用 allKeys
方法获取键数组,然后将该数组写入 plist。
HTH
终于!!
经过大量更改...非常感谢您的 Mach 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];
}
我正在我的设备中使用 theos 创建 JB 调整。
我想读一个像这样的 plist 字典:
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];
}
谢谢!
因为你的 plist 是一个 字典 使用 NSDictionary
中的 dictionaryWithContentsOfFile:
(而不是 NSArray
中的 arrayWithContentsOfFile:
)。有了字典后,您可以使用 allKeys
方法获取键数组,然后将该数组写入 plist。
HTH
终于!!
经过大量更改...非常感谢您的 Mach 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];
}