I want to convert the function in Swift or Objective-C so I can use in Native module of React Native.
export const provisionWithCertificate = async (
scopeId,
registrationId,
keyPath,
certificatePath,
) => {
const data = {
registrationId: registrationId,
};
const cert = await RNFS.readFile(certificatePath, 'utf8');
const key = await RNFS.readFile(keyPath, 'utf8');
try {
const httpsAgent = new https.Agent({
cert: cert,
key: key,
});
console.log('httpsAgent', httpsAgent);
const response = await axios({
method: 'PUT',
url: `https://global.azure-devices-provisioning.net/${scopeId}/registrations/${registrationId}/register?api-version=2021-06-01`,
data: data,
httpsAgent: httpsAgent,
headers: {
'Content-Type': 'application/json',
'Content-Encoding': 'utf-8',
},
});
return response.data;
} catch (err) {
console.log('err', err);
return err;
}
};
I tried this using some AI to convert but I am not able find the satisfactory solution.