调用目标app中某个实例的方法,问题是这样的

微信下方的TabBar(MMTabBarController )有新消息会弹出Badge数字,我想修改这个数字。在cycript里可以直接通过choose获取到MMTabBarController 实例,然后调用实例的方法

  • (void)setTabBarBadgeValue:(int)arg1 forIndex:(int)arg2;

但是,在THEOS里应该如何实现呢?

下面是MMTabBarController的头文件:
#import “UITabBarController.h”

@class MMDelegateProxy, NSMutableArray, UITapGestureRecognizer;

@interface MMTabBarController : UITabBarController
{
unsigned long _viewControllersCount;
NSMutableArray *_tabBarBtns;
NSMutableArray *_badgeViews;
UITapGestureRecognizer *_doubleTapGesture;
BOOL _hasDoubleTapGesture;
}

  • (void)willAnimateRotationToInterfaceOrientation:(int)arg1 duration:(double)arg2;
  • (unsigned int)supportedInterfaceOrientations;
  • (BOOL)shouldAutorotateToInterfaceOrientation:(int)arg1;
  • (void)setTabBarBadgeImage:(id)arg1 forIndex:(unsigned int)arg2;
  • (void)setTabBarBadgeString:(id)arg1 forIndex:(int)arg2;
  • (void)setTabBarBadgeValue:(int)arg1 forIndex:(int)arg2;
  • (id)getViewControllerAtIndex:(unsigned long)arg1;

在cycript里可以通过
cy#var tabbar = choose(MMTabBarController)[0]
#"<MMTabBarController: 0x7dcd8d0>"
获得,也可以一步一步这样获得:
cy#var tabbar = [UIApplication sharedApplication].keyWindow.rootViewController
#"<MMTabBarController: 0x7dcd8d0>"
调用方法:cy#[tabbar setTabBarBadgeValue:5 forIndex:0]

hook这个MMTabBarController的某个前期调用的方法,拿到MMTabBarController对象,存成一个全局变量,在有需要的时候直接调用

直接hook住MMTabBarController然后将self存入static的变量里也可以吗?

可以,retain一下,然后在你的代码里释放

明白了!:lol: