2016-10-03 20 views
0

したがって、特定のアプリのアプリバッジをバンドルIDで設定しようとしています。私はSpringBoardに夢中にしてすべてアプリを特定の文字列に設定していますが、1つのアプリケーションアイコンのバッジ文字列を設定する方法が見つからないようです。私は現在、投げてるのエラーは次のとおりです。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++とJava/javaScriptでの経験があるので、基本的なアイデアのプログラミングを理解しています。

答えて

0

免責事項:私はSpringBoardに精通していません。

プロパティとしてではなく、メソッドとしてbadgeNumberOrStringを定義しました。

あなたのようSBApplicationControllerでそれを追加した場合:

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

@property NSString *badgeNumberOrString; 

@end 

それはそれに応じて設定されるでしょう、そしてあなたはゲッターをオーバーライドして上に行くことができます。

あなたはメソッド単位を使用したい場合、あなたは自分の他の方法のように括弧を使用する必要があります。

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

しかし、あなたはプロパティにアクセスしようとしているので、この行はまだ機能していないだろう - その値を設定し、その値を設定します:

this.badgeNumberOrString = @"" 
+0

私はbadgeNumberOrStringプロパティにアクセスしてフック内で変更できる方法はありますか? –

+0

SBApplicationControllerはbagdeNumberOfStringプロパティを持たないNSObjectから継承しています。したがって、自分でそのプロパティを作成する必要があります。 – EDUsta

+0

ああ、説明してくれてありがとう。 –

関連する問題