格子集成带来未处理的承诺拒绝

 收藏

I've just started development in react-native. I want to integrate the Plaid API with in my app. Plaid provided the link client react-native library through which we would make payments. I've followed all the guideline provided at GitHub but failed to get the desired results.

The example they've shared works fine with vanilla-react-native project but it doesn't work with expo-generated-project.

以下是我遇到博览会的例外情况:

Possible Unhandled Promise Rejection (id: 5):
TypeError: Cannot read property 'create' of undefined
TypeError: Cannot read property 'create' of undefined
    at openLink$ (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:142091:52)
    at tryCatch (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:29388:19)
    at Generator.invoke [as _invoke] (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:29564:24)
    at Generator.prototype.<computed> [as next] (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:29431:23)
    at tryCatch (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:29388:19)
    at invoke (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:29464:22)
    at http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:29494:13
    at tryCallTwo (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:3372:7)
    at doResolve (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:3536:15)
    at new Promise (http://127.0.0.1:19001/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:3395:5)

TypeError: Cannot read property 'create' of undefined
    at openLink$ (PlaidLink.js:27)
    at tryCatch (runtime.js:45)
    at Generator.invoke [as _invoke] (runtime.js:274)
    at Generator.prototype.<computed> [as next] (runtime.js:97)
    at tryCatch (runtime.js:45)
    at invoke (runtime.js:135)
    at runtime.js:170
    at tryCallTwo (core.js:45)
    at doResolve (core.js:200)
    at new Promise (core.js:66)

该库的源代码:

export const openLink = async ({ onExit, onSuccess, ...serializable }) => {
  if (Platform.OS === 'android') {
    const constants = NativeModules.PlaidAndroid.getConstants();
    NativeModules.PlaidAndroid.startLinkActivityForResult(
      JSON.stringify(serializable),
      result => {
        switch (result.resultCode) {
          case constants.RESULT_SUCCESS:
            if (onSuccess != null) {
              onSuccess(result.data);
            }
            break;
          case constants.RESULT_CANCELLED:
          case constants.RESULT_EXIT:
            if (onExit != null) {
              onExit(result.data);
            }
            break;
        }
      },
    );
  } else {
    NativeModules.RNLinksdk.create(serializable); // this is the line where I'm getting error
    NativeModules.RNLinksdk.open((error, metadata) => {
      if (error) {
        if (onExit != null) {
          var data = metadata || {};
          data.error = error;
          onExit(data);
        }
      } else {
        switch (metadata.status) {
          case 'connected':
            if (onSuccess != null) {
              onSuccess(metadata);
            }
            break;
          default:
            if (onExit != null) {
              onExit(metadata);
            }
            break;
        }
      }
    });
  }
};

实际实现:

const HomeScreen = () => {
  return (
    <View>
    <PlaidLink
        publicKey='750eb33cc63a1860caa68a98c165a4'
        clientName='5e7c5d3912884a001116ab4a'
        env='sandbox'  // 'sandbox' or 'development' or 'production'
        product={['transactions']}
        onSuccess={data => console.log('success: ', data)}
        onExit={data => console.log('exit: ', data)}
        onCancelled = {(result) => {console.log('Cancelled: ', result)}}>
      <Text>Add Account</Text>
</PlaidLink>
  </View>
  )
};

const styles = StyleSheet.create({});

export default HomeScreen;

我读过,expo不支持外部库的链接。因此,无论如何,如果我需要使用这些库,则需要从expo toolKit中弹出。

谁能指导我,这个问题我们有其他选择吗?还是我们有更好的实施方法?提前致谢。

回复