【问题标题】:Integrate Parse-SDK-JS to react antive app集成 Parse-SDK-JS 以响应原生应用程序
【发布时间】: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);

【问题讨论】:

    标签: javascript react-native parse-server parse-cloud-code


    【解决方案1】:

    您需要从parse/react-native.js 导入 Parse。应该是这样的:

    import Parse, { Error } from 'parse/react-native.js';
    

    【讨论】:

      猜你喜欢
      • 2016-12-06
      • 1970-01-01
      • 1970-01-01
      • 2020-03-10
      • 1970-01-01
      • 2016-08-23
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      相关资源
      最近更新 更多