0

そのため、バンドル ID で特定のアプリのアプリ バッジを設定しようとしています。SpringBoard に接続して、すべてのアプリを特定の文字列に設定しましたが、単一のアプリケーション アイコンにバッジ文字列を設定する方法が見つからないようです。現在スローされているエラーは次のとおりです。

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

Tweak.xm の現在のコードは次のとおりです。

#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

編集: SBApplicationIcon.sharedInstance を applicationWithBundleIdentifier などから分離し、次のようにつなぎ合わせる必要があることに気付きました。

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

しかし、どのオブジェクト タイプに保存すればよいかわかりません。私はまだlogos/objective-c環境に慣れていません。私は C++ と Java/JavaScript の経験があるので、プログラミングの基本的な考え方を理解しています。

4

1 に答える 1

1

免責事項: 私は 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 = @""
于 2016-10-04T08:34:14.063 に答える