ios - 从首选项包中读取 BOOL 值

标签 ios jailbreak tweak

我正在尝试从 PSSwitchCell 读取 BOOL 值,但 BOOL 始终为 true。这是我的代码( Logo 调整(iOSopendev))

这是 .xm 文件,我使用 iosopendev Logo 调整模板和简单的首选项加载器。

另外,我知道这只是一个简单的调整,但我正在学习这一切是如何工作的。我看过在线教程,但我似乎不明白为什么这不起作用。

#import <UIKit/UIKit.h>
#define plist_path @"/Library/PreferenceLoader/Preferences/MyTweak.plist" 

#define listenToNotification$withCallBack(notification, callback);CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)&callback, CFSTR(notification), NULL, CFNotificationSuspensionBehaviorHold);
%hook SBApplicationIcon

+ (id)sharedInstance
{
%log;

return %orig;
}

static NSMutableDictionary *plistDict = nil;
static void loadSettings(void) {
if (plistDict) {
    [plistDict release];
    plistDict = nil;
}
plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:plist_path];

}
-(void)launch
{
    NSString *number = [[[plistDict objectForKey:@"enabled"] intValue];

    if ([number isEqualto:@"1"]) {
    NSString *appName = [self displayName];
    NSString *message = [NSString stringWithFormat:@"The app %@ has been launched", appName, nil];
    UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:appName message:message delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
      alert1.delegate = self;
    [alert1 show];
    [alert1 release]; }
else {
    //Do nothing!
}
%orig;
}

- (void)messageWithNoReturnAndOneArgument:(id)originalArgument
{
%log;

%orig(originalArgument);

// or, for exmaple, you could use a custom value instead of the original argument: %orig(customValue);
}

- (id)messageWithReturnAndNoArguments
{
    %log;
    id originalReturnOfMessage = %orig;

// for example, you could modify the original return value before returning it:   [SomeOtherClass doSomethingToThisObject:originalReturnOfMessage];

return originalReturnOfMessage;
}

%end
%ctor {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    %init;
    listenToNotification$withCallBack("dylankelly.MyDev.MyTweak-preferencesChanged", loadSettings);
    loadSettings();
    [pool drain];
}

这是我的 plist(其中一部分)文件,它显示在设置中。

<dict>
    <key>cell</key>
        <string>PSSwitchCell</string>
        <key>default</key>
        <integer>0</integer>
        <key>defaults</key>
        <string>dylankelly.MyDev.MyTweak</string>
        <key>TrueValue</key>
        <integer>1</integer>
        <key>FalseValue</key>
        <integer>0</integer>
        <key>key</key>
        <string>enabled</string>
        <key>label</key>
        <string>Show</string>
        <key>PostNotification</key>
        <string>dylankelly.MyDev.MyTweak-preferencesChanged</string>

</dict>

最佳答案

您不能将 BOOL 存储在 plist 或字典中,因为它不是对象。将您的值保存为 NSNumbers; @(0) 表示 false,@(1) 表示 true。

您可以将以下数据类型作为值存储在 .plist 文件中:

-NSArray 
-NSMutableArray 
-NSDictionary 
-NSMutableDictionary 
-NSData
-NSMutableData 
-NSString 
-NSMutableString 
-NSNumber 
-NSDate

关于ios - 从首选项包中读取 BOOL 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16064949/

相关文章:

ios - 在没有首选项的情况下在 iOS 中获取 iPhone 位置 位置服务设置为 ON

iphone - 为越狱的 iOS 制作守护进程

ios - 在iOS 7中阻止传入的短信

ios - 在 theos 中编译调整时出错

ios - 如何在 iOS 7(越狱)中获取 SpringBoard 的任务端口?

ios - 在 Xcode 机器人上运行单元测试后生成 .gcda 文件

ios - Xcode 5 持续集成 CodeSign 失败

ios - Xcode 6 无法启动 (OS X 10.9.4)

iphone - 这个平移手势识别器 Action 有什么问题?

iphone - ios 使用越狱浏览其他应用程序文件夹