简体   繁体   中英

react-native error RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL)

I am trying to use react-native-fbsdk in my react-native app. It was working fine untill yesterday. But, today it gives a weird error stating RCTJSONStringify() encountered the following error: Invalid type in JSON write (NSURL).

RN v0.42.0

Here is my code:

  _fbAuth(error, result) {
    if (error) {
      console.log("error");
      alert("login has error: " + result.error);
    } else if (result.isCancelled) {
      console.log("login cancelled");
      alert("login is cancelled.");
    } else {
      AccessToken.getCurrentAccessToken().then((data) => {
        console.log("login success");
        console.log(data.accessToken.toString());
        let accessToken = data.accessToken;
        alert(data.accessToken.toString());
        const responseInfoCallback = (error, result) => {
          if (error) {
            console.log(error);
          } else {
            console.log(result);
          }
        }

        const infoRequest = new GraphRequest(
          '/me',
          {
            accessToken: accessToken,
            parameters: {
              fields: {
                string: 'email,name,first_name,middle_name,last_name'
              }
            }
          },
          responseInfoCallback
        );

        // Start the graph request.
        new GraphRequestManager().addRequest(infoRequest).start();
      });
    }
  }

  render() {
    console.log("in new render");
    return (
      <View style={styles.container}>
      <LoginButton
        publishPermissions={["publish_actions"]}
        onLoginFinished={this._fbAuth}
        onLogoutFinished={() => alert("logout.")}/>
      </View>
    );
  }

The error information printed in debugger:

错误信息

I get the above error while calling the graphAPI in the function responseInfoCallback . Any ideas what is happening ?

Update 1:

This error happens only when remote debugger is turned on!! Else it is not happening. But without remote debugger, I cannot proceed with developing the app. Are there any other methods to see log statements of react-native app other than remote debugger ?

Update 2:

The RCTJSONStringify() error happens only behind proxy. And also https fetch calls does not work under proxy. I tested in an open network, it works fine. I guess, it is to add some proxy information to RN app. I think it is related to APP transport security

If you turn the debugger off, you can see the proper error in the XCode console. Access it from Xcode menu View/Debug Area/Activate console, if it's not enabled automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM