因此,我尝试通过捆绑 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 方面的经验,所以我了解编程的基本思想。