iosobjective-cjailbreaktheoslogos

iOS SpringBoard property badgeNumberOrString not found on object of id


So I'm trying to set the app badge for a particular app by bundle ID. I've hooked into SpringBoard and set all apps to a specific string before this, but I can't seem to find a way to set the badge string for a single application icon. The error I'm getting thrown currently is:

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

My current code in Tweak.xm is:

#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

EDIT: I noticed that I should be separating the SBApplicationIcon.sharedInstance from the applicationWithBundleIdentifier, etc. and piecing it together like so:

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

But I'm not sure what object types I should save them to. I'm still very new to the logos/objective-c environment. I have experience in C++ and Java/javaScript so I understand programming basic ideas.


Solution

  • Disclaimer: I'm not familiar with SpringBoard.

    You've defined badgeNumberOrString as a method, not as a property.

    If you add it in SBApplicationController like:

    @interface SBApplicationController : NSObject
    + (id)sharedInstance;
    - (id)applicationWithBundleIdentifier:(id)arg1;
    
    @property NSString *badgeNumberOrString;
    
    @end
    

    It'll be set accordingly, and you can go on with overriding the getter.

    If you wanted to use method-wise, you need to use brackets just like in your other methods:

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

    But this line would still not be working since you're trying to access a property -which is not available- and set its value:

    this.badgeNumberOrString = @""