2016-10-03 19 views
0

그래서 번들 ID로 특정 앱에 대한 앱 배지를 설정하려고합니다. 나는 SpringBoard에 접속하여이 전에 특정 문자열에 개의 응용 프로그램을 모두 으로 설정했지만 단일 응용 프로그램 아이콘의 배지 문자열을 설정하는 방법을 찾지 못하는 것 같습니다. 나는 현재 던져지고있어 오류 : Tweak.xm에서iOS SpringBoard 속성 badgeNumberOrString이 id 객체에 없습니다.

Tweak.xm:28:123: error: property 'badgeNumberOrString' not found on object of 
     type 'id' 
    ...applicationWithBundleIdentifier:@"com.apple.AppStore"].badgeNumberOrStri.. 
                  ^
1 error generated. 
make[3]: *** [/home/theodd/Desktop/appbadge/.theos/obj/debug/armv7/Tweak.xm.94fb86bd.o] Error 1 
make[2]: *** [/home/theodd/Desktop/appbadge/.theos/obj/debug/armv7/AppBadge.dylib] Error 2 
make[1]: *** [internal-library-all_] Error 2 
make: *** [AppBadge.all.tweak.variables] Error 2 

내 현재 코드는 다음과 같습니다

#import <SpringBoard/SpringBoard.h> 
#define PLIST_PATH @"/var/mobile/Library/Preferences/com.theodd.appbadge.plist" 

inline bool GetPrefBool(NSString *key){ 
    return [[[NSDictionary dictionaryWithContentsOfFile:PLIST_PATH] valueForKey:key] boolValue]; 
} 

inline NSString* GetPrefString(NSString *key){ 
    return [[NSDictionary dictionaryWithContentsOfFile:PLIST_PATH] objectForKey:key]; 
} 

inline NSString* appID(NSString *key) { 
    return [[[NSBundle mainBundle] infoDictionary] objectForKey:key]; 
} 

@interface SBApplicationIcon : NSObject 
- (void)setBadge:(id)arg1; 
@end 

@interface SBApplicationController : NSObject 
+ (id)sharedInstance; 
- (id)applicationWithBundleIdentifier:(id)arg1; 
@end 

BOOL isEnabled = GetPrefBool(@"enableSwitch"); 
NSString* bString = GetPrefString(@"badgeName"); 

NSString* appStoreString = [SBApplicationController.sharedInstance applicationWithBundleIdentifier:@"com.apple.AppStore"].badgeNumberOrString; 

%hook SBApplication 
- (id)badgeNumberOrString { 
    id r = %orig; 
    if(isEnabled) return bString; 
    return r; 
} 

%end 

편집 : 나는 내가 applicationWithBundleIdentifier에서 SBApplicationIcon.sharedInstance을 분리해야 것으로 나타났습니다, 등등. 그리고 이렇게 함께 연결 :

that = SBApplicationController.sharedInstance, 
then this = [that applicationWithBundleIdentifier:@""], 
this.badgeNumberOrString = @"" 

그러나 나는 그들을 구해야 할 개체 유형을 잘 모르겠습니다. 나는 여전히 로고/목표 -C 환경에 대해 매우 새롭다. C++ 및 Java/javaScript 경험이 있으므로 프로그래밍 기본 개념을 이해합니다.

답변

0

면책 조항 : 저는 SpringBoard에 익숙하지 않습니다.

badgeNumberOrString을 속성이 아닌 메서드로 정의했습니다.

@interface SBApplicationController : NSObject 
+ (id)sharedInstance; 
- (id)applicationWithBundleIdentifier:(id)arg1; 

@property NSString *badgeNumberOrString; 

@end 
그것은 적절하게 설정됩니다

, 당신은 게터를 오버라이드 (override)과에 갈 수 있습니다 : 당신이 좋아하는 SBApplicationController에 추가 할 경우

.

당신이, 당신은 단지 다른 방법처럼 괄호를 사용해야 할 방법이 많다는 사용하고자하는 경우 :

NSString* appStoreString = [[SBApplicationController.sharedInstance applicationWithBundleIdentifier:@"com.apple.AppStore"] badgeNumberOrString]; 

그러나 당신이 속성에 액세스하기 위해 노력하고 있기 때문에이 라인은 여전히 ​​작동하지 않을 것입니다 - 그 값을 설정할 수 없습니다 :

this.badgeNumberOrString = @"" 
+0

badgeNumberOrString 속성에 액세스하여 훅 내부에서 수정할 수있는 방법이 있습니까? –

+0

SBApplicationController는 bagdeNumberOfString 속성이없는 NSObject를 상속합니다. 따라서, 당신은 그 속성을 직접 만들어야합니다. – EDUsta

+0

오, 해명 해줘서 고마워. –