iOS集成weex踩坑记录

2021-07-01  本文已影响0人  送我迷迭香

1.iOS 14系统,图片不显示

解决方法
1.找到WXLayer.m文件,修改

- (void)display{
    {
    if(@available(iOS 14.0, *)) {
    [super display];
    }
    [self.wx_component _willDisplayLayer:self];
    }
}

2.修改WXImageComponent.m文件

将

((UIImageView *)strongSelf.view).image = image;

修改为

strongSelf.view.layer.contents = (__bridge id _Nullable)(image.CGImage);

图片即可显示
image.png
2.新界面无法隐藏导航栏

解决方案: 自定义NavigationHandler 实现WXNavigationProtocol 协议,重写了push方法,push跳转到自定义控制器 FBWXRootViewController

[WXSDKEngine registerHandler:[FBWXNavigationHandlerImpl new] withProtocol:@protocol(WXNavigationProtocol)];
- (id)navigationControllerOfContainer:(UIViewController *)container {
    return container.navigationController;
}

- (void)popViewControllerWithParam:(NSDictionary *)param completion:(WXNavigationResultBlock)block withContainer:(UIViewController *)container {
    BOOL animated = YES;
    id obj = [param objectForKey:@"animated"];
    if (obj) {
        animated = [WXConvert BOOL:obj];
    }
    [container.navigationController popViewControllerAnimated:animated];
}

- (void)pushViewControllerWithParam:(NSDictionary *)param completion:(WXNavigationResultBlock)block withContainer:(UIViewController *)container {
    BOOL animated = YES;
    NSString *obj = [[param objectForKey:@"animated"] lowercaseString];
    if (obj && [obj isEqualToString:@"false"]) {
        animated = NO;
    }
    
    FBWXRootViewController *vc = [[FBWXRootViewController alloc]initWithSourceURL:[NSURL URLWithString:param[@"url"]]];
    vc.hidesBottomBarWhenPushed = YES;
    [container.navigationController pushViewController:vc animated:animated];
}

3.weex storage方法在iOS无法直接调用

解决方案: WXStorageModule 在源码中是私有的 ,方法不对外提供 所以在项目中重写了一套,并且注册了同样的module覆盖weex本身的module,该方法要在registerDefaults 后调用

[WXSDKEngine registerModule:@"storage" withClass:[FBCustomStorageModule class]];

    FBCustomStorageModule *storageModule = [[FBCustomStorageModule alloc]init];
    
    [storageModule setItem:@"accessToken" value:fbAccountInfo.accessToken callback:^(id result) {
        
    }];
    
    NSDictionary *userInfoDict = fbAccountInfo.mj_keyValues;

    [storageModule setItem:@"loginData" value: [NSString convertToJsonData:userInfoDict] callback:^(id result) {
        
    }];
上一篇 下一篇

猜你喜欢

热点阅读