Skip to content

Commit 291fd61

Browse files
committed
Merge pull request #7 from chrisinsfo/ProvidePermissionsManager
Provide Permissions Manager to conform to APCOnboardingManagerProvider
2 parents da4b598 + 4cef305 commit 291fd61

File tree

2 files changed

+62
-38
lines changed

2 files changed

+62
-38
lines changed

Diabetes/Startup/APHAppDelegate.m

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,6 @@ - (void)enableBackgroundDeliveryForHealthKitTypes
160160

161161
- (void) setUpInitializationOptions
162162
{
163-
NSDictionary *permissionsDescriptions = @{
164-
@(kAPCSignUpPermissionsTypeLocation) : NSLocalizedString(@"Using your GPS enables the app to accurately determine distances travelled. Your actual location will never be shared.", nil),
165-
@(kAPCSignUpPermissionsTypeCoremotion) : NSLocalizedString(@"Using the motion co-processor allows the app to determine your activity, helping the study better understand how activity level may influence disease.", nil),
166-
@(kAPCSignUpPermissionsTypeMicrophone) : NSLocalizedString(@"Access to microphone is required for your Voice Recording Activity.", nil),
167-
@(kAPCSignUpPermissionsTypeLocalNotifications) : NSLocalizedString(@"Allowing notifications enables the app to show you reminders.", nil),
168-
@(kAPCSignUpPermissionsTypeHealthKit) : NSLocalizedString(@"On the next screen, you will be prompted to grant GlucoSuccess access to read and write some of your general and health information, such as height, weight and steps taken so you don't have to enter it again.", nil),
169-
};
170163

171164
NSMutableDictionary * dictionary = [super defaultInitializationOptions];
172165

@@ -179,35 +172,7 @@ - (void) setUpInitializationOptions
179172
[dictionary addEntriesFromDictionary:@{
180173
kStudyIdentifierKey : kStudyIdentifier,
181174
kAppPrefixKey : kAppPrefix,
182-
kBridgeEnvironmentKey : @(self.environment),
183-
kHKReadPermissionsKey : @[
184-
HKQuantityTypeIdentifierBodyMass,
185-
HKQuantityTypeIdentifierHeight,
186-
HKQuantityTypeIdentifierStepCount,
187-
HKQuantityTypeIdentifierDietaryCarbohydrates,
188-
HKQuantityTypeIdentifierDietarySugar,
189-
HKQuantityTypeIdentifierDietaryEnergyConsumed,
190-
HKQuantityTypeIdentifierBloodGlucose,
191-
@{kHKWorkoutTypeKey : HKWorkoutTypeIdentifier},
192-
@{kHKCategoryTypeKey : HKCategoryTypeIdentifierSleepAnalysis}
193-
],
194-
kHKWritePermissionsKey : @[
195-
HKQuantityTypeIdentifierBodyMass,
196-
HKQuantityTypeIdentifierHeight
197-
],
198-
kAppServicesListRequiredKey : @[
199-
@(kAPCSignUpPermissionsTypeLocalNotifications),
200-
@(kAPCSignUpPermissionsTypeCoremotion)
201-
],
202-
kAppServicesDescriptionsKey : permissionsDescriptions,
203-
kAppProfileElementsListKey : @[
204-
@(kAPCUserInfoItemTypeEmail),
205-
@(kAPCUserInfoItemTypeBiologicalSex),
206-
@(kAPCUserInfoItemTypeHeight),
207-
@(kAPCUserInfoItemTypeWeight),
208-
@(kAPCUserInfoItemTypeWakeUpTime),
209-
@(kAPCUserInfoItemTypeSleepTime),
210-
]
175+
kBridgeEnvironmentKey : @(self.environment)
211176
}];
212177

213178
self.initializationOptions = dictionary;
@@ -703,7 +668,7 @@ - (void)configureObserverQueries
703668
return stringToWrite;
704669
};
705670

706-
NSArray* dataTypesWithReadPermission = self.initializationOptions[kHKReadPermissionsKey];
671+
NSArray* dataTypesWithReadPermission = [self healthKitQuantityTypesToRead];
707672

708673
if (!self.passiveDataCollector)
709674
{
@@ -822,6 +787,65 @@ - (APCScene *)customInfoSceneForOnboarding:(APCOnboarding *) __unused onboarding
822787
return scene;
823788
}
824789

790+
-(APCPermissionsManager * __nonnull)permissionsManager
791+
{
792+
return [[APCPermissionsManager alloc] initWithHealthKitCharacteristicTypesToRead:[self healthKitCharacteristicTypesToRead]
793+
healthKitQuantityTypesToRead:[self healthKitQuantityTypesToRead]
794+
healthKitQuantityTypesToWrite:[self healthKitQuantityTypesToWrite]
795+
userInfoItemTypes:[self userInfoItemTypes] signUpPermissionTypes:[self signUpPermissionsTypes]];
796+
}
797+
798+
- (NSArray *)healthKitCharacteristicTypesToRead
799+
{
800+
return @[
801+
HKCharacteristicTypeIdentifierBiologicalSex,
802+
HKCharacteristicTypeIdentifierDateOfBirth
803+
];
804+
}
805+
806+
- (NSArray *)healthKitQuantityTypesToWrite
807+
{
808+
return @[
809+
HKQuantityTypeIdentifierBodyMass,
810+
HKQuantityTypeIdentifierHeight
811+
];
812+
}
813+
814+
- (NSArray *)healthKitQuantityTypesToRead
815+
{
816+
return @[
817+
HKQuantityTypeIdentifierBodyMass,
818+
HKQuantityTypeIdentifierHeight,
819+
HKQuantityTypeIdentifierStepCount,
820+
HKQuantityTypeIdentifierDietaryCarbohydrates,
821+
HKQuantityTypeIdentifierDietarySugar,
822+
HKQuantityTypeIdentifierDietaryEnergyConsumed,
823+
HKQuantityTypeIdentifierBloodGlucose,
824+
@{kHKWorkoutTypeKey : HKWorkoutTypeIdentifier},
825+
@{kHKCategoryTypeKey : HKCategoryTypeIdentifierSleepAnalysis}
826+
];
827+
}
828+
829+
- (NSArray *)signUpPermissionsTypes
830+
{
831+
return @[
832+
@(kAPCSignUpPermissionsTypeLocalNotifications),
833+
@(kAPCSignUpPermissionsTypeCoremotion)
834+
];
835+
}
836+
837+
- (NSArray *)userInfoItemTypes
838+
{
839+
return @[
840+
@(kAPCUserInfoItemTypeEmail),
841+
@(kAPCUserInfoItemTypeBiologicalSex),
842+
@(kAPCUserInfoItemTypeHeight),
843+
@(kAPCUserInfoItemTypeWeight),
844+
@(kAPCUserInfoItemTypeWakeUpTime),
845+
@(kAPCUserInfoItemTypeSleepTime),
846+
];
847+
}
848+
825849
#pragma mark - Consent
826850

827851
- (ORKTaskViewController *)consentViewController

0 commit comments

Comments
 (0)