react-native-health
react-native-health copied to clipboard
AppleHealthKit.initHealthKit's callback never executed on Xcode build
Describe the bug
As title states, the initHealthKit callback function is never executed resulting in requests to AHK failing with message:
{ code: 'ECOM.APPLE.HEALTHKIT5',
message: 'Authorization not determined',
domain: 'com.apple.healthkit',
userInfo: { NSLocalizedDescription: 'Authorization not determined' },
nativeStackIOS:
[ '0 APPNAME 0x00000001005f2004 RCTJSErrorFromCodeMessageAndNSError + 100',
'1 APPNAME 0x00000001005f1f64 RCTJSErrorFromNSError + 204',
'2 APPNAME 0x000000010050614c __67-[RCTAppleHealthKit(Methods_Sleep) sleep_getSleepSamples:callback:]_block_invoke + 160',
'3 APPNAME 0x000000010050f73c __85-[RCTAppleHealthKit(Queries) fetchSleepCategorySamplesForPredicate:limit:completion:]_block_invoke + 292',
'4 libdispatch.dylib 0x00000001814b5924 07C1CA26-9AB4-3FFA-A69E-F00308628A9C + 10532',
'5 libdispatch.dylib 0x00000001814b7670 07C1CA26-9AB4-3FFA-A69E-F00308628A9C + 18032',
'6 libdispatch.dylib 0x00000001814bedf4 07C1CA26-9AB4-3FFA-A69E-F00308628A9C + 48628',
'7 libdispatch.dylib 0x00000001814bf99c 07C1CA26-9AB4-3FFA-A69E-F00308628A9C + 51612',
'8 libdispatch.dylib 0x00000001814ca1b8 07C1CA26-9AB4-3FFA-A69E-F00308628A9C + 94648',
'9 libsystem_pthread.dylib 0x00000001f265e0f4 _pthread_wqthread + 288',
'10 libsystem_pthread.dylib 0x00000001f265de94 start_wqthread + 8' ]
}
This, however, only seems to happen when the app is built with Xcode, and does not happen if I just run npm run iOS
for example.
This has only recently started happening, but I have not change the version of react-native-health that I use. I do not recall if there has been an iOS update that may have caused this.
To Reproduce
Steps to reproduce the behavior:
- Delete existing app on iPhone
- Open an App project with Xcode
- Verify that app has "HealthKit" capability
- Clear the build (cmd + shift + k)
- Change build configuration to production (Ccmd + shif + ,)
- Run/Build
- Check console logs
Expected behavior
I expect, given the code snippet below, that either the success or error console print statements are executed and that I am able to fetch data from AHK
Smartphone (please complete the following information):**
- Device: iPhone 11 Pro
- OS: 15
Additional context
I've tried moving where the init function is called and also tried removing and re-adding the Health kit capabilities via Xcode but it hasn't changed anything.
The following is a snippet of code used for the init. The messages that are printed/output are:
2021-11-15 12:50:36.492271-0500 APPNAME[4022:884309] [javascript] 'initAHK', { permissions:
{ read:
[ 'HeartRate',
'StepCount',
'SleepAnalysis',
'Weight',
'RestingHeartRate',
'Steps' ],
write: [] } }
2021-11-15 12:50:36.492327-0500 APPNAME[4022:884309] [javascript] { [Function] type: 'async' }
Nothing inside the callback is printed out.
import AppleHealthKit, { HealthKitPermissions } from "react-native-health";
export const AHKPermissions = {
permissions: {
read: [
AppleHealthKit.Constants.Permissions.HeartRate,
AppleHealthKit.Constants.Permissions.StepCount,
AppleHealthKit.Constants.Permissions.SleepAnalysis,
AppleHealthKit.Constants.Permissions.Weight,
AppleHealthKit.Constants.Permissions.RestingHeartRate,
AppleHealthKit.Constants.Permissions.Steps,
],
write: [],
},
} as HealthKitPermissions;
export const initAHK = () => {
console.log("initAHK", AHKPermissions);
console.log(AppleHealthKit.initHealthKit); // Check if function is undefined.
AppleHealthKit.initHealthKit(AHKPermissions, (error: string) => {
/* Called after we receive a response from the system */
if (error) {
throw new Error("[ERROR] AHK cannot grant permissions!");
}
/* Can now read or write to HealthKit */
console.log("initAHK success");
});
};
@macelai Would you be able to take a look at this? Is there anything else I can provide to help debug this? Would you be able to give me advice on what other steps I can take to debug this?
@shmkane Hey, sorry but I don't have the skills to help you with that
@macelai Do you happen to know any collaborators on this project that would be able to assist with this? I'd greatly appreciate tagging them to this
@AugustoRamos94 do you think you can help here?