美文网首页iOS开发知识小集
集成Weex到iOS已有应用中

集成Weex到iOS已有应用中

作者: 我在花屋敷等你 | 来源:发表于2019-01-25 11:20 被阅读1次

结合官方文档配置

1、导入官方SDK

pod 'WeexSDK'//配置podfile后pod install

2、didFinishLaunchingWithOptions中初始化环境

下面是官方提供的初始化代码

//business configuration
[WXAppConfiguration setAppGroup:@"AliApp"];
[WXAppConfiguration setAppName:@"WeexDemo"];
[WXAppConfiguration setAppVersion:@"1.0.0"];

//init sdk environment
[WXSDKEngine initSDKEnvironment];

//register custom module and component,optional
[WXSDKEngine registerComponent:@"MyView" withClass:[MyViewComponent class]];
[WXSDKEngine registerModule:@"event" withClass:[WXEventModule class]];

//register the implementation of protocol, optional
[WXSDKEngine registerHandler:[WXNavigationDefaultImpl new] withProtocol:@protocol(WXNavigationProtocol)];

//set the log level
[WXLog setLogLevel: WXLogLevelAll];

测试学习时可以注释掉报错的内容,并且修改WXLogLevelAll为WXLogLevelError可以减少Log信息。

3、渲染 weex Instance

Weex 支持整体页面渲染和部分渲染两种模式,你需要做的事情是用指定的 URL 渲染 Weex 的 view,然后添加到它的父容器上,父容器一般都是 viewController。

#import <WeexSDK/WXSDKInstance.h>
- (void)viewDidLoad
{
    [super viewDidLoad];

    _instance = [[WXSDKInstance alloc] init];
    _instance.viewController = self;
    _instance.frame = self.view.frame;

    __weak typeof(self) weakSelf = self;
    _instance.onCreate = ^(UIView *view) {
        [weakSelf.weexView removeFromSuperview];
        weakSelf.weexView = view;
        [weakSelf.view addSubview:weakSelf.weexView];
    };

    _instance.onFailed = ^(NSError *error) {
        //process failure
    };

    _instance.renderFinish = ^ (UIView *view) {
        //process renderFinish
    };
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"js"];
    [_instance renderWithURL:url options:@{@"bundleUrl":[self.url absoluteString]} data:nil];
}

销毁weex Instance

- (void)dealloc
{
    [_instance destroyInstance];
}

4、导入 Weex SDK framework 到工程

这步具体的操作可以参考官方文档
http://weex.apache.org/cn/guide/integrate-to-your-app.html
这里值得注意的是,在添加依赖时,官方要求的依赖如下图:

image.png
苹果在XCode10中移除了libstdc++(libstdc++.6、libstdc++6.0.9)库,XCode10以上版本的可以删除libstdc++(libstdc++.6、libstdc++6.0.9)库,然后添加libc++库来解决此问题。

参考文档:
http://weex.apache.org/cn/guide/integrate-to-your-app.html

相关文章

网友评论

    本文标题:集成Weex到iOS已有应用中

    本文链接:https://www.haomeiwen.com/subject/xhhujqtx.html