Commit 84423f99 authored by 王品堯's avatar 王品堯

把保存Anchor的動作變成RCT_EXPORT_METHOD讓JS端控制是否改變Anchor

parent 00aca5f1
......@@ -19,6 +19,7 @@
61232F931E303758000A5026 /* RCTAppleHealthKit+Methods_Mindfulness.m in Sources */ = {isa = PBXBuildFile; fileRef = 61232F921E303758000A5026 /* RCTAppleHealthKit+Methods_Mindfulness.m */; };
64C42D4A1D351A8800A0A8F7 /* RCTAppleHealthKit+Methods_Vitals.m in Sources */ = {isa = PBXBuildFile; fileRef = 64C42D491D351A8800A0A8F7 /* RCTAppleHealthKit+Methods_Vitals.m */; };
64E0E73F1D37947B00EAB905 /* RCTAppleHealthKit+Methods_Results.m in Sources */ = {isa = PBXBuildFile; fileRef = 64E0E73E1D37947B00EAB905 /* RCTAppleHealthKit+Methods_Results.m */; };
83C70EFC1FDFA6BB00AD7AA9 /* RCTAppleHealthKit+NSUserDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 83C70EFB1FDFA6BB00AD7AA9 /* RCTAppleHealthKit+NSUserDefaults.m */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -58,6 +59,8 @@
64C42D491D351A8800A0A8F7 /* RCTAppleHealthKit+Methods_Vitals.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+Methods_Vitals.m"; sourceTree = "<group>"; };
64E0E73D1D37947B00EAB905 /* RCTAppleHealthKit+Methods_Results.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTAppleHealthKit+Methods_Results.h"; sourceTree = "<group>"; };
64E0E73E1D37947B00EAB905 /* RCTAppleHealthKit+Methods_Results.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+Methods_Results.m"; sourceTree = "<group>"; };
83C70EFA1FDFA59300AD7AA9 /* RCTAppleHealthKit+NSUserDefaults.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RCTAppleHealthKit+NSUserDefaults.h"; sourceTree = "<group>"; };
83C70EFB1FDFA6BB00AD7AA9 /* RCTAppleHealthKit+NSUserDefaults.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RCTAppleHealthKit+NSUserDefaults.m"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -112,6 +115,8 @@
377D44F21D247D0A004E35CB /* RCTAppleHealthKit+Methods_Characteristic.m */,
37837E7B1DCFE270000201A0 /* RCTAppleHealthKit+Methods_Sleep.h */,
37837E7C1DCFE270000201A0 /* RCTAppleHealthKit+Methods_Sleep.m */,
83C70EFA1FDFA59300AD7AA9 /* RCTAppleHealthKit+NSUserDefaults.h */,
83C70EFB1FDFA6BB00AD7AA9 /* RCTAppleHealthKit+NSUserDefaults.m */,
);
path = RCTAppleHealthKit;
sourceTree = "<group>";
......@@ -181,6 +186,7 @@
64C42D4A1D351A8800A0A8F7 /* RCTAppleHealthKit+Methods_Vitals.m in Sources */,
3774C8931D2092F20000B3F3 /* RCTAppleHealthKit.m in Sources */,
377D44F31D247D0A004E35CB /* RCTAppleHealthKit+Methods_Characteristic.m in Sources */,
83C70EFC1FDFA6BB00AD7AA9 /* RCTAppleHealthKit+NSUserDefaults.m in Sources */,
3774C89E1D2095850000B3F3 /* RCTAppleHealthKit+TypesAndPermissions.m in Sources */,
3774C8D71D20C65F0000B3F3 /* RCTAppleHealthKit+Methods_Fitness.m in Sources */,
);
......
//
// RCTAppleHealthKit+NSUserDefaults.h
// RCTAppleHealthKit
//
// Created by rosswang on 2017/12/12.
// Copyright © 2017年 Greg Wilson. All rights reserved.
//
#import "RCTAppleHealthKit.h"
@interface RCTAppleHealthKit (Methods_UserDefaults)
- (void)set_UserDefaultsByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)reset_UserDefaultsByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end
//
// RCTAppleHealthKit+NSUserDefaults.m
// RCTAppleHealthKit
//
// Created by rosswang on 2017/12/12.
// Copyright © 2017年 Greg Wilson. All rights reserved.
//
#import "RCTAppleHealthKit+NSUserDefaults.h"
#import "RCTAppleHealthKit+Utils.h"
@implementation RCTAppleHealthKit (Methods_UserDefaults)
- (void)set_UserDefaultsByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
NSString *str = [input objectForKey:@"key"];
NSData *newAnchor = [[NSUserDefaults standardUserDefaults] objectForKey:[@"New" stringByAppendingString:str]];
[[NSUserDefaults standardUserDefaults] setObject:newAnchor forKey:[@"Old" stringByAppendingString:str]];
NSDictionary *result = @{
@"status" : @(true)
};
callback(@[[NSNull null], result]);
}
- (void)reset_UserDefaultsByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
NSString *str = [input objectForKey:@"key"];
[[NSUserDefaults standardUserDefaults] setObject:HKAnchoredObjectQueryNoAnchor forKey:[@"Old" stringByAppendingString:str]];
NSDictionary *result = @{
@"status" : @(true)
};
callback(@[[NSNull null], result]);
}
@end
......@@ -515,7 +515,7 @@
}
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:newAnchor];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:quantityType.identifier];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:[RCTAppleHealthKit stringFromType:quantityType status:false]];
if (completion) {
NSMutableArray *data = [NSMutableArray arrayWithCapacity:1];
......@@ -582,7 +582,7 @@
}
};
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:quantityType.identifier];
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:[RCTAppleHealthKit stringFromType:quantityType status:true]];
HKQueryAnchor *anchor = [NSKeyedUnarchiver unarchiveObjectWithData:data];
HKAnchoredObjectQuery *anchorQuery = [[HKAnchoredObjectQuery alloc] initWithType:quantityType
......@@ -610,7 +610,7 @@
}
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:newAnchor];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:quantityType.identifier];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:[RCTAppleHealthKit stringFromType:quantityType status:false]];
if (completion) {
NSMutableArray *data = [NSMutableArray arrayWithCapacity:1];
......@@ -644,7 +644,7 @@
}
};
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:quantityType.identifier];
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:[RCTAppleHealthKit stringFromType:quantityType status:true]];
HKQueryAnchor *anchor = [NSKeyedUnarchiver unarchiveObjectWithData:data];
HKAnchoredObjectQuery *anchorQuery = [[HKAnchoredObjectQuery alloc] initWithType:quantityType
......@@ -672,7 +672,7 @@
}
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:newAnchor];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:categoryType.identifier];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:[RCTAppleHealthKit stringFromType:categoryType status:false]];
if (completion) {
NSMutableArray *data = [NSMutableArray arrayWithCapacity:1];
......@@ -739,7 +739,7 @@
}
};
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:categoryType.identifier];
NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:[RCTAppleHealthKit stringFromType:categoryType status:true]];
HKQueryAnchor *anchor = [NSKeyedUnarchiver unarchiveObjectWithData:data];
HKAnchoredObjectQuery *anchorQuery = [[HKAnchoredObjectQuery alloc] initWithType:categoryType
......
......@@ -33,4 +33,6 @@
+ (NSMutableArray *)reverseNSMutableArray:(NSMutableArray *)array;
+ (NSString *)stringFromType:(HKSampleType *)type status:(bool)status;
@end
......@@ -320,4 +320,21 @@
return array;
}
+ (NSString *)stringFromType:(HKSampleType *)type status:(bool)status {
NSString *str = status ? @"Old" : @"New";
if ([type isEqual:[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeartRate]]) {
str = [str stringByAppendingString:@"HeartRateSync"];
}
if ([type isEqual:[HKCorrelationType correlationTypeForIdentifier:HKCorrelationTypeIdentifierBloodPressure]]) {
str = [str stringByAppendingString:@"BloodPressureSync"];
}
if ([type isEqual:[HKObjectType categoryTypeForIdentifier:HKCategoryTypeIdentifierSleepAnalysis]]) {
str = [str stringByAppendingString:@"SleepSync"];
}
if ([type isEqual:[HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount]]) {
str = [str stringByAppendingString:@"StepCountSync"];
}
return str;
}
@end
......@@ -16,6 +16,7 @@
#import "RCTAppleHealthKit+Methods_Results.h"
#import "RCTAppleHealthKit+Methods_Sleep.h"
#import "RCTAppleHealthKit+Methods_Mindfulness.h"
#import "RCTAppleHealthKit+NSUserDefaults.h"
#import <React/RCTBridgeModule.h>
#import <React/RCTEventDispatcher.h>
......@@ -195,6 +196,15 @@ RCT_EXPORT_METHOD(saveMindfulSession:(NSDictionary *)input callback:(RCTResponse
[self mindfulness_saveMindfulSession:input callback:callback];
}
RCT_EXPORT_METHOD(setUserDefaults:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self set_UserDefaultsByKey:input callback:callback];
}
RCT_EXPORT_METHOD(resetUserDefaults:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self reset_UserDefaultsByKey:input callback:callback];
}
- (void)isHealthKitAvailable:(RCTResponseSenderBlock)callback
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment