We have a react-native application that uses react-native-keychain library in this way (like in this issue):
import * as Keychain from 'react-native-keychain';
try {
Keychain.setInternetCredentials(
'device-id',
'RANDOMDATA',
DeviceInfo.getUniqueID().toString(),
{ accessGroup: 'org.reactjs.native.example.myreactapp'})
.then(() => console.log('Done'))
} catch (err) {
console.log("error save", err)
}
I would like to be able to retrieve this data in my today widget made in swift, I would need to know the storage key for that. Below is the way I'm supposed to get it back on the widget:
let itemKey = "device-id"
let keychainAccessGroupName = "3P********.org.reactjs.native.example.myreactapp"
let queryLoad: [String: AnyObject] = [
kSecClass as String: kSecClassGenericPassword,
kSecAttrAccount as String: itemKey as AnyObject,
kSecReturnData as String: kCFBooleanTrue,
kSecMatchLimit as String: kSecMatchLimitOne,
kSecAttrAccessGroup as String: keychainAccessGroupName as AnyObject
]
var result: AnyObject?
let resultCodeLoad = withUnsafeMutablePointer(to: &result) {
SecItemCopyMatching(queryLoad as CFDictionary, UnsafeMutablePointer($0))
}
if resultCodeLoad == noErr {
if let result = result as? Data,
let keyValue = NSString(data: result,
encoding: String.Encoding.utf8.rawValue) as String? {
// Found successfully
print("device-id : ", keyValue)
}
} else {
print("Error loading from Keychain: \(resultCodeLoad)")
}
The code below come from this blog
But it doesn't work. As you may have noticed I need to pass the device-id to the widget because unlike Android the UUID often changes and we get a different ID on each part which prevents the widget from working properly