W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
建議在DEBUG模式下依賴
在工程目錄的 podfile 添加如下代碼
source https://github.com/CocoaPods/Specs.git
pod 'WXDevtool', '0.24.0', :configurations => ['Debug']
可以通過更新本地 podspec repo,pod search 來查詢最新版本,在 podfile 文件添加依賴。
git clone git@github.com:weexteam/weex-devtool-iOS.git
?在相對(duì)較大的互聯(lián)網(wǎng) App 研發(fā)中, framework 靜態(tài)庫被廣泛應(yīng)用,所以推薦使用方法一接入。
參考?PlayGround
?中的實(shí)現(xiàn)
//方法1 pod依賴方式
#import <WXDevtool/WXDevtool.h>
//方法2 源碼依賴方式
#import "WXDevtool.h"
查看 WXDevtool 頭文件如下:
@interface WXDevTool : NSObject
+ (void)setDebug:(BOOL)isDebug;
+ (BOOL)isDebug;
+ (void)launchDevToolDebugWithUrl:(NSString *)url;
@end
?setDebug
?:參數(shù)為 ?YES
? 時(shí),直接開啟調(diào)試模式,反之關(guān)閉,使用場景如下所述
如果你的應(yīng)用中存在掃碼功能或即將集成掃碼功能,推薦使用該方式進(jìn)行集成,Demo 地址見: Playground App
核心代碼為獲取掃碼鏈接中的?_wx_devtoo
?l參數(shù),并將調(diào)試工具與調(diào)試服務(wù)器鏈接:
[WXDevTool launchDevToolDebugWithUrl:@"ws://{ip}:{port}/debugProxy/native/{channelid}"];
如果你需要直接讓你的應(yīng)用鏈接上Weex調(diào)試工具,你需要通過如下方式進(jìn)行集成:
weex debug --port 8888 --channelid 1
? 去指定端口號(hào)及調(diào)試進(jìn)程ID.{ip}
?,?{port}
?,?{channelid}
?為你本地的值。[WXDevTool setDebug:NO];
[WXDevTool launchDevToolDebugWithUrl:@"ws://{ip}:{port}/debugProxy/native/{channelid}"];
如果程序一啟動(dòng)就開啟 Weex 調(diào)試,需要在 WeexSDK 引擎初始化之前添加代碼,同時(shí)需要將Debug開關(guān)設(shè)置為?NO
?,進(jìn)入調(diào)試界面后再打開?JS Debug
?開關(guān)(服務(wù)鏈接時(shí)對(duì)于純weex項(xiàng)目會(huì)丟失首屏Weex頁面的消息導(dǎo)致白屏)。
WXDemoViewController.m
? 例子在 Weex 頁面初始化或 ?viewDidLoad
? 方法時(shí)添加注冊通知,舉例如下[[NSNotificationCenter defaultCenter] addObserver:self selector:notificationRefreshInstance: name:@"RefreshInstance" object:nil];
最后千萬記得在 ?dealloc
? 方法中取消通知,如下所示
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
頁面刷新實(shí)現(xiàn),先銷毀當(dāng)前 instance,然后重新創(chuàng)建 instance,舉例如下:
- (void)render
{
CGFloat width = self.view.frame.size.width;
[_instance destroyInstance];
_instance = [[WXSDKInstance alloc] init];
_instance.viewController = self;
_instance.frame = CGRectMake(self.view.frame.size.width-width, 0, width, _weexHeight);
__weak typeof(self) weakSelf = self;
_instance.onCreate = ^(UIView *view) {
[weakSelf.weexView removeFromSuperview];
weakSelf.weexView = view;
[weakSelf.view addSubview:weakSelf.weexView];
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, weakSelf.weexView);
};
_instance.onFailed = ^(NSError *error) {
};
_instance.renderFinish = ^(UIView *view) {
[weakSelf updateInstanceState:WeexInstanceAppear];
};
_instance.updateFinish = ^(UIView *view) {
};
if (!self.url) {
return;
}
NSURL *URL = [self testURL: [self.url absoluteString]];
NSString *randomURL = [NSString stringWithFormat:@"%@?random=%d",URL.absoluteString,arc4random()];
[_instance renderWithURL:[NSURL URLWithString:randomURL] options:@{@"bundleUrl":URL.absoluteString} data:nil];
}
說明:目前版本需要注冊的通知名稱為固定的 “RefreshInstance”,下個(gè)版本會(huì)添加用戶自定義 name 。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: