我正在使用theos创建一个调整,将"滑动解锁"文本更改为自定义字符串
在我的Tweak.xm:
%hook SBLockScreenView
- (void)setCustomSlideToUnlockText:(id)unlockText {
NSString *settingsPath = @"/var/mobile/Library/Preferences/com.motion.tweak~prefs.plist";
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:settingsPath];
NSString *text = [prefs objectForKey:@"text"];
BOOL enabled = [prefs objectForKey:@"enabled"];
if([text isEqualToString:@""] || text == nil || ![enabled]) {
%orig(unlockText);
}
else if ([enabled]) {
unlockText = text;
%orig(unlockText);
}
}
%end
当我尝试制作包时,我返回了一个错误:
error: cannot initialize a variable of type 'BOOL' (aka 'signed char')
with an rvalue of type 'id'
BOOL enabled = [prefs objectForKey:@"enabled"];
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
第一期:
正如@Tim Edwards所说:从字典返回的布尔对象将作为NSNumber返回(可以是0或1)。因此,请使用询问NSNumber的布尔值
[ [prefs objectForKey:@"enabled"] booleanValue]
就下一个错误代码而言,是因为您对if语句进行了错误检查:
if([text isEqualToString:@""] || text == nil || ![enabled]) {
else if ([enabled]) {
您不需要将布尔值放在括号[]中,而且最好只检查NSString的长度,而不是对其进行2次检查,因此将两个语句都更改为:
// I am accustomed with making it <= 0 even though it's impossible.
if(!enabled || text.length <= 0) {
else if (enabled) {