React Native开发经验集React Native开发React Native实践

reactnative 数据持久化-realm共用(三)

2018-08-17  本文已影响25人  DaZenD

realm 共用

https://stackoverflow.com/questions/40428923/realm-react-native-and-objective-c

rn

1:yarn add realm --save

这时候,如果直接运行,会错误:红屏错误
Cannot read property 'debugHosts' of undefined

2:react-native link realm
链接原生库

运行正常

native - ios

1:pod ‘Realm’

这时候运行失败:
pod 集成的realm中的librealmcore-ios.a 和 rn 链接原生库libRealmReact.a 有字段重复定义

duplicateerror.png

2:将pod集成的realm需要的静态库删除

这时候运行报错:

nativeerror.png

3:将rn链接原生库libRealmReact.a删除,报红屏错误:Cannot read property 'debugHosts' of undefined

具体问题演示

问题演示

注:很恶心,无法上传pdf,这个链接可能打开的草鸡慢,抱歉,下面官方沟通记录里也有

官方回应

沟通记录

I did some research and found that the reason you may been running into issues is that Realm can't support two SDKs at the same time. When you begin working with realm objects there is no way to convert the format from framework to framework.

I'm sorry if this doesn't work your use case. Our engineering is aware of the problem and may work on it in the future.

20180626

跟官方沟通暂时不支持

1:Dynamic Framework
2:cocoapods
3:Static Framework(ios only)。后续验证

2:cocoapds方式集成依然不行,后续跟进删除一方的文件依赖试试。但是感觉不行,因为rn,native中关于realm的依赖方式不同。

3:环境可行

20180627

方案

https://stackoverflow.com/questions/40428923/realm-react-native-and-objective-c

1:native 提供方法 共rn调用:RCTBridgeModule。在方法上更统一

2:各自独立访问,感觉在结构上更合理一些。

Access Control

指定路径:ios 》 rn

rn中:
realm中的对象属性总是可选的,不需要显式地指定,也不需要指定。默认optional

field:‘type’ (required)
filed:‘type?’ (optional)
filed:{type:‘type’, optional:true/false}

native-ios:
复写requiredproperties方法,return @[@“filed”,@“filed”]; 指定字段是required的。需要显示指定required/optional

解决方式:保持两端permission一致即可
1:required
2:optional

其他相关资料

个人rn相关专题

上一篇 下一篇

猜你喜欢

热点阅读