2013-04-17 1 views
0

Я пытаюсь прочитать значение BOOL из PSSwitchCell, но BOOL просто подходит к истине все время. Это мой код (логотип tweak (iOSopendev))Чтение значения BOOL из предпочтительного набора

Это .xm-файл, im с использованием шаблона настройки логотипа iosopendev и простого загрузчика предпочтений.

Кроме того, я знаю, что это просто простая настройка, но я изучаю, как все это работает. Я посмотрел учебники онлайн, но я не могу понять, почему это не работает.

#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]; 
} 

Это мой файл (часть его), который отображается в настройках.

<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> 
+1

Это не связано с Xcode любыми средствами. И отформатируйте свой код. – 2013-04-17 16:06:52

+0

Извините, я отформатировал его. – DylanKelly

+1

Он не выглядит форматированным для меня. Если вы хотите, чтобы люди вам помогли, вам нужно приложить некоторые усилия, чтобы представить свой код в читаемой форме. –

ответ

1

Вы не можете хранить BOOL в plist или словаре, поскольку это не объект. Сохраните ваши значения как NSNumbers; @ (0) для false и @ (1) для true.

Вы можете хранить следующие типы данных в .plist файле в качестве значения:

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

Спасибо за ответ! я изменил plist, и метод запуска выше, будет ли это работать? – DylanKelly

+0

Сделайте снимок и дайте мне знать :) – JonahGabriel

+0

он дает ошибку, говорящий, что не может инициализировать переменную типа NSString со значением типа int, в этой строке NSString * number = [[plistDict objectForKey: @ " enabled "] intValue]; – DylanKelly

Смежные вопросы