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

它将被相应地设置,您可以继续覆盖 getter。

如果您想按方法使用,则需要像在其他方法中一样使用括号:

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

但是这条线仍然无法正常工作,因为您正在尝试访问一个不可用的属性并设置它的值:

this.badgeNumberOrString = @""
于 2016-10-04T08:34:14.063 回答