2013-04-17 3 views
0

PSSwitchCell에서 BOOL 값을 읽으려고하고 있지만 BOOL이 항상 true로 설정됩니다. 이것은 내 코드입니다 (로고 비틀기 (iOSopendev))기본 설정 번들의 BOOL 값 읽기

이것은 iosopendev 로고 팅크 템플릿과 간단한 환경 설정 로더를 사용하는 .xm 파일입니다.

또한 이건 그냥 간단하게 조정할 수 있음을 알고 있지만이 모든 작동 방식을 배우고 있습니다. 나는 자습서를 온라인에서 보았다. 그러나 나는 이것이 작동하지 않는 이유를 볼 수 없다.

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

이 어떤 방법으로 엑스 코드 관련이 없습니다. 그리고 코드를 포맷하십시오. –

+0

죄송합니다, 형식을 지정했습니다. – DylanKelly

+1

포맷되어 있지 않습니다. 사람들이 당신을 도울 수 있기를 원하면 코드를 읽을 수있는 형태로 제시해야합니다. –

답변

1

BOOL은 객체가 아니므로 plist 또는 사전에 저장할 수 없습니다. 값을 NSNumbers로 저장하십시오. false는 @ (0)이고 true는 @ (1)입니다.

당신은 값으로 .plist 파일에 다음과 같은 데이터 유형을 저장할 수 있습니다 :

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

답변 해 주셔서 감사합니다! 위의 실행 방법과 plist를 변경했습니다. 이것이 효과가 있습니까? – DylanKelly

+0

알려주세요 :) – JonahGabriel

+0

이 줄에 int 유형의 값으로 NSString 형식의 변수를 초기화 할 수 없다는 오류가 발생합니다. NSString * number = [[plistDict objectForKey : @ " enabled "] intValue]; – DylanKelly