有興趣的可以簡單看看, 當(dāng)時微信是沒有切換功能, 所以自己寫一個, 現(xiàn)在官方推出了切換功能 ,就沒啥用了
轉(zhuǎn)載請注明出處
平時用的微信號和王者榮耀游戲的號是兩個,游園驚夢的時候需要每天都登陸游戲號, 天天要退出, 切換賬號, 輸入賬號密碼, 太麻煩了,所以寫了一個插件, 用于切換
我是基于Tweak編寫的
第一步, 在設(shè)置界面添加了一個切換賬號的cell
#import "src/WeChatHeader.h"
#import "substrate.h"
int myValue = 0;
%hook NewSettingViewController
- (void)reloadTableData {
%orig;
MMTableViewInfo *tableViewInfo = MSHookIvar<id>(self, "m_tableViewInfo");
MMTableViewSectionInfo *sectionInfo = [%c(MMTableViewSectionInfo) sectionInfoDefaut];
MMTableViewCellInfo *settingCell = [%c(MMTableViewCellInfo) normalCellForSel:@selector(switchAccount) target:self title:@"切換賬號" accessoryType:1];
[sectionInfo addCell:settingCell];
[tableViewInfo insertSection:sectionInfo At:0];
MMTableView *tableView = [tableViewInfo getTableView];
[tableView reloadData];
}
第二步,cell的點擊事件
// 點擊事件
%new
- (void)switchAccount {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"確認(rèn)切換?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSLog(@"確定");
myValue = 1;
WCActionSheet * sheet = MSHookIvar<id>(self,"m_logOutActionSheet");
NSLog(@"確定111");
[self actionSheet:sheet clickedButtonAtIndex:1];
NSLog(@"確定222");
}];
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
NSLog(@"取消");
}];
[alertController addAction:action1];
[alertController addAction:action2];
[self presentViewController:alertController animated:YES completion:nil];
}
%end
效果圖:

6FC2B7D411982CB03816D8A75FE7F099.png
通過分析, 登陸界面的登陸按鈕的事件是-(void)onNext 然后賬號, 密碼,手機(jī)號的輸入都是通過WCAccountTextFieldItem這個控件的-(void)setText:(id)arg1方法進(jìn)行賦值
第三步,在正常退出后的界面, 點擊切換賬號的方法, 提取出來了
value是干什么呢, 區(qū)分是正常退出切換和插件自動切換用的
%hook WCAccountLoginLastUserViewController
- (void)viewDidLoad
{
%orig;
NSLog(@"myvalue ??= %d",myValue);
if(myValue)
{
WCAccountLoginControlLogic * change = [[%c(WCAccountLoginControlLogic) alloc]init];
WCUIActionSheet * action = [[%c(WCUIActionSheet) alloc]init];
[change onLastUserChangeAccount:action];
}
}
%end
第四步,點擊切換完成后輸入手機(jī)號/qq賬號
因為我自己的賬號一個是qq和密碼登陸, 一個是手機(jī)號+密碼,所以會有判斷,需要用哪個接口登陸
%hook WCAccountMainLoginViewController
- (void)viewDidLoad
{
%orig;
if(myValue)
{
//(CAppUtil) getLastPhoneNumber 獲取當(dāng)前賬號綁定手機(jī)的,用于判定當(dāng)前賬號是哪個, 你們也可以用別的來判斷
if([[%c(CAppUtil) getLastPhoneNumber] isEqualToString:@"+8618201301234"])
{
WCAccountTextFieldItem * phone = MSHookIvar<id>(self,"_textFieldPhoneNumberItem");
[phone setText:@"15000471234"];
[self onNext];
}
else if([[%c(CAppUtil) getLastPhoneNumber] isEqualToString:@"+8615000471234"])
{
WCAccountTextFieldItem * username = MSHookIvar<id>(self,"_textFieldUserNameItem");
WCAccountTextFieldItem * pwd = MSHookIvar<id>(self,"_textFieldUserPwdItem");
[username setText:@"775931234"];
[pwd setText:@"1234456"];
[self switchToUserLogin];
[self onNext];
}
}
}
%end
switchToUserLogin 是切換到qq號和密碼界面, 然后調(diào)用那個界面的onNext
最后一步,登陸,myValue = 0; 恢復(fù)成正常狀態(tài), 以免影響正常退出之后的登陸
%hook WCAccountNewPhoneVerifyViewController
- (void)viewDidLoad
{
%orig;
if(myValue)
{
WCAccountTextFieldItem * phone = MSHookIvar<id>(self,"_textFieldPwdItem");
[phone setText:@"1234456"];
[self onNext];
myValue = 0;
}
}
%end
對了, 還有一個頭文件WeChatHeader.h
@interface CAppUtil : NSObject
+ (id)getLastPhoneNumber;
@end
@interface WCAccountLoginControlLogic : UIViewController
- (void)onLastUserChangeAccount:(id)arg1;
@end
@interface WCAccountLoginLastUserViewController : UIViewController
- (void)actionSheet:(id)arg1 clickedButtonAtIndex:(long long)arg2;
- (void)showInView:(id)arg1;
@end
@interface WCActionSheet : UIActionSheet
- (void)showInView:(id)arg1;
@end
@interface WCUIActionSheet : WCActionSheet
@end
@interface WCAccountTextFieldItem : NSObject
- (void)setText:(id)arg1;
- (id)getTextField;
@end
@interface WCAccountMainLoginViewController : UIViewController
- (void)onNext;
- (void)switchToUserLogin;
@end
@interface WCAccountNewPhoneVerifyViewController : UIViewController
//@property (nonatomic ,strong) WCAccountTextFieldItem *textFieldPwdItem;
//
//@property (nonatomic ,strong) WCAccountTextFieldItem *textFieldVerifyCodeItem;
- (void)onNext;
@end
@interface NewSettingViewController: MMUIViewController
- (void)reloadTableData;
- (void)actionSheet:(id)arg1 clickedButtonAtIndex:(long long)arg2;
// 退出, 哪個都可以, 具體不知道是哪個
- (void)tryQuit;
- (void)finalQuit;
@end