简体   繁体   English

react-native-sensitive-info 无法读取未定义的属性 setItem

[英]react-native-sensitive-info Cannot read property setItem of undefined

Issue问题

react-native-sensitive-info isn't working on iOS, I keep getting the error "setItem is undefined" because it seems SInfo is not loading properly. react-native-sensitive-info 在 iOS 上不起作用,我不断收到错误“setItem is undefined”,因为 SInfo 似乎没有正确加载。

I can launch perfectly on Android though.不过,我可以在 Android 上完美启动。

What I've tried我试过的

I've tried multiple different values and placing it in many different points in my code.我尝试了多个不同的值并将其放置在我的代码中的许多不同点。 Currently I'm using the first example outlined on their Github and it's still not working.目前我正在使用他们 Github 上概述的第一个示例,但它仍然无法正常工作。

Code代码

import React from 'react';
import { 
  StyleSheet, 
  AsyncStorage 
} from 'react-native';

import firebase from 'react-native-firebase';
import SInfo from 'react-native-sensitive-info';
import SplashScreen from 'react-native-splash-screen';
import AppContainer from './Components/BottomTabNav';


export default class App extends React.Component {
  constructor(props) {
    super();
    this.state = {
       userData: {}
    };
      SInfo.setItem('key1', 'value1', {
          sharedPreferencesName: 'mySharedPrefs',
          keychainService: 'myKeychain'
        }).then((value) =>
          console.log(value) //value 1
        )
  }

If anyone has any suggestions that would be great!如果有人有任何建议,那就太好了! Thanks in advance for your help!在此先感谢您的帮助!

It's seems to a be quirk of the library on iOS where protected data isn't always available on app start...这似乎是 iOS 库的一个怪癖,其中受保护的数据在应用程序启动时并不总是可用......

See issue (unresolved): https://github.com/mCodex/react-native-sensitive-info/issues/326查看问题(未解决): https ://github.com/mCodex/react-native-sensitive-info/issues/326

See comment in library code: https://github.com/mCodex/react-native-sensitive-info/blob/master/ios/RNSensitiveInfo/RNSensitiveInfo.m#L263请参阅库代码中的注释: https ://github.com/mCodex/react-native-sensitive-info/blob/master/ios/RNSensitiveInfo/RNSensitiveInfo.m#L263

The less than ideal workaround (for now) seems to be to wrap the RNSInfo access in a try catch and keep re-trying until there is no error.不太理想的解决方法(目前)似乎是将 RNSInfo 访问包装在 try catch 中并继续重试直到没有错误。

You may need some sort of throttling here though with a limit on the number of retries.尽管重试次数有限制,但您可能需要在此处进行某种限制。 You won't want to keep retrying infinitely if there is some other kind of error being thrown.如果抛出某种其他类型的错误,您将不希望继续无限重试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 "React-Native AsyncStorage:TypeError:无法读取未定义的属性“setItem”" - React-Native AsyncStorage: TypeError: Cannot read property 'setItem' of undefined 无法读取属性 '#<webview> ' 未定义的反应本机</webview> - Cannot read property '#<WebView>' of undefined react native 反应本机“无法读取未定义的属性” AsyncStorage - React native 'Cannot read property of undefined' AsyncStorage React Native无法读取属性未定义错误 - React Native cannot read property undefined error React Native 无法读取未定义的属性“导航” - React Native Cannot read property 'navigate' of undefined 无法读取未定义的属性“ info” - Cannot read property 'info' of undefined 反应本机如何处理无法读取未定义的属性“未定义” - react native how to deal with Cannot read property 'undefined' of undefined React Native Image Picker无法读取未定义的属性“ showImagePicker” - React Native Image Picker cannot read property “showImagePicker” of undefined 无法在react-native上下文api中读取未定义的属性“状态”? - Cannot read property 'state' of undefined in react-native context api? React Native jest test:TypeError:无法读取未定义的属性&#39;unsubscribeFromTopic&#39; - React Native jest test: TypeError: Cannot read property 'unsubscribeFromTopic' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM