集成 Parse-SDK-JS 以响应原生应用程序
Posted
技术标签:
【中文标题】集成 Parse-SDK-JS 以响应原生应用程序【英文标题】:Integrate Parse-SDK-JS to react antive app 【发布时间】:2020-09-22 09:41:13 【问题描述】:我试图用谷歌搜索一些指南或教程,但没有找到。有什么方法可以将 Parse SDK 集成到我的 react-native 应用程序中,就像 android 和 ios 方式一样?因为我尝试集成 Parse-SDK-JS,但它现在无法运行我的应用程序,崩溃并出现错误 Error: Unable to resolve module crypto from node_modules\parse\node_modules\crypto-js\core.js: crypto could not be found within the project.'
我的代码:
parse.ts:
// In a React Native application
import Parse, Error from 'parse';
// On React Native >= 0.50 and Parse >= 1.11.0, set the Async
import AsyncStorage from 'react-native';
export const initParse = () =>
Parse.setAsyncStorage(AsyncStorage);
Parse.initialize('xxxxxxxxxxxxxxxxxxxxxxxxxxx'); //APP_ID
Parse.serverURL = 'https://xxx.herokuapp.com/parse'; //HEROKU URI SERVER
;
export const testCreate = () =>
const GameScore = Parse.Object.extend('GameScore');
const gameScore = new GameScore();
gameScore.set('score', 1337);
gameScore.set('playerName', 'Sean Plott');
gameScore.set('cheatMode', false);
gameScore.save().then(
(gameScore: any) =>
// Execute any logic that should take place after the object is saved.
alert('New object created with objectId: ' + gameScore.id);
,
(error: Error) =>
// Execute any logic that should take place if the save fails.
// error is a Parse.Error with an error code and message.
alert('Failed to create new object, with error code: ' + error.message);
,
);
;
index.js:
/**
* @format
*/
import
AppRegistry
from 'react-native';
import
initParse
from './src/library/parse/parse';
import App from './App';
import
name as appName
from './app.json';
initParse();
AppRegistry.registerComponent(appName, () => App);
【问题讨论】:
【参考方案1】:您需要从parse/react-native.js
导入 Parse。应该是这样的:
import Parse, Error from 'parse/react-native.js';
【讨论】:
以上是关于集成 Parse-SDK-JS 以响应原生应用程序的主要内容,如果未能解决你的问题,请参考以下文章
是否可以将 Google Hangouts 原生集成到 Android 应用程序中?