微信切換賬號

有興趣的可以簡單看看, 當(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

最后,有可能會有bug,會不適用于你 , 思路就是這么個思路 ,和方法, 可以參考參考, 主要也是針對我的情況,非常方便, 切換很快

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 2017.02.22 可以練習(xí),每當(dāng)這個時候,腦袋就犯困,我這腦袋真是神奇呀,一說讓你做事情,你就犯困,你可不要太...
    Carden閱讀 1,490評論 0 1
  • 吃貨地圖產(chǎn)品需求文檔 V1.0-2015/03/30 1概述 1.1產(chǎn)品概述及目標(biāo) 概述:“吃貨地圖”是一款基于i...
    michaelshan閱讀 5,985評論 1 46
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,068評論 25 709
  • 添加本地通知需要進(jìn)入項目的project->Capabilities把Push Notifications打開,并...
    zgsddzwj閱讀 661評論 0 0
  • 我在海邊尋覓你的蹤跡,你卻在那朵浪花里藏匿,我柔柔的呼喚你名字,你又在海中的礁石間藏匿,我坐在海岸雙手合十,想象你...
    馬嘉喜歡深呼吸閱讀 152評論 0 2

友情鏈接更多精彩內(nèi)容