KjellConnelly / react-native-shared-group-preferences

127 stars 57 forks source link

iOS原生获取的值,控制台打印出来会多出来一个符号,字符串外面包裹着双引号 #34

Open inkcrazy666 opened 1 year ago

inkcrazy666 commented 1 year ago

RN 端去存储

...other code
this.saveUserDataToSharedStorage('userData');
......

async saveUserDataToSharedStorage(data) {
    try {
      await SharedGroupPreferences.setItem(
        'savedData',
        data,
        Config.APP_GROUP_IDENTIFIER_FOR_IOS,
      );
      this.loadUsernameFromSharedStorage();
    } catch (errorCode) {
      // errorCode 0 = There is no suite with that name
      console.log(errorCode);
    }
  }

  async loadUsernameFromSharedStorage() {
    try {
      const loadedData = await SharedGroupPreferences.getItem(
        'savedData',
        Config.APP_GROUP_IDENTIFIER_FOR_IOS,
      );
      console.log('loadedData===', loadedData);
      console.log('loadedData===', 'userData');
    } catch (errorCode) {
      // errorCode 0 = no group name exists. You probably need to setup your Xcode Project properly.
      // errorCode 1 = there is no value for that key
      console.log(errorCode);
    }
  }

ios 原生去获取

     if let userData = userDefaults?.value(forKey: "savedData") as? String {
        let string = "普通string"
        print("userData===", userData)
        print("普通string===", string)
      }

userData=== "userData"(理论上应该打印的结果是:userData,然而它的结果是:"userData",多了一对符号) 普通string=== 普通string 截屏2023-09-13 15 54 24

我现在必须多写如下代码:let token = tokenStr.trimmingCharacters(in: CharacterSet(charactersIn: "\"")),否则我就拿不到正确的token