我正在嘗試構建一款專注於Android的RN應用程序。我決定使用領域看到它的所有好評。所以,我在MainActivity中添加了import和package,並運行了react-native鏈接領域,但我仍然遇到一些錯誤。嘗試將Realm導入React Native應用程序時出現多個錯誤
這裏是我到目前爲止的代碼:
import Realm from 'realm'
import _ from 'lodash'
const profileId = 'e72d7aa7-43e4-4095-a5c0-71fe08f6c4df';
var realm = new Realm({
schema: [{
name: 'Profile',
properties: {
id: 'string',
profileVersion: 'number',
firstName: 'string',
lastName: 'string',
profilePicBase64: 'string'
}
}
]});
if(_.head(realm.objects('Profile')) === undefined){
realm.write(() => {
realm.create('Profile', {
id: profileId,
profileVersion: -1,
firstName: '',
lastName: '',
profilePicBase64: ''
})
})
}
export default {
getProfile :() => _.head(realm.objects('Profile')),
setProfile: (profile) => {
realm.write(() => {
profile.id = profileId;
realm.create('Profile', profile, true)
})
}
}
我打算使用的DbContext作爲訪問數據庫,並以抽象的這一層的單點位
現在,如果我運行應用程序通常(不是在調試器中一步一步地),我得到:缺少領域構造函數 - 請確保包含RealmReact框架!在RSOD(死亡的紅色屏幕)中。 8082與
碼:(有它的境界節點模塊中的index.js文件根目錄)
如果我在調試器中運行它,它在rpc.js試圖訪問本地主機發生故障時, 19 POST http://localhost:8082/create_session 網::執行線路時ERR_CONNECTION_REFUSED
:
request.open('POST', url, false);
request.send(body);
再說什麼寫在文檔中,我沒有做任何其他領域的工作。
關於如何解決此問題的任何想法?