Commit 44ff14d0 authored by 王品堯's avatar 王品堯

記錄timestamp的檔案

parent 9320bc3c
...@@ -13,4 +13,7 @@ ...@@ -13,4 +13,7 @@
- (void)set_UserDefaultsByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)set_UserDefaultsByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)reset_UserDefaultsByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback; - (void)reset_UserDefaultsByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)get_TimestampByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
- (void)set_TimestampByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback;
@end @end
...@@ -32,4 +32,43 @@ ...@@ -32,4 +32,43 @@
callback(@[[NSNull null], result]); callback(@[[NSNull null], result]);
} }
- (void)get_TimestampByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
NSString *key = [input objectForKey:@"key"];
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSString *filePath = [url.path stringByAppendingPathComponent:key];
NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
if (content != nil) {
NSDictionary *result = @{
@"timestamp" : content
};
callback(@[[NSNull null], result]);
} else {
callback(@[[NSNull null]]);
}
}
- (void)set_TimestampByKey:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback
{
NSString *key = [input objectForKey:@"key"];
NSString *timestamp = [input objectForKey:@"timestamp"];
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSString *filePath = [url.path stringByAppendingPathComponent:key];
NSError *error;
BOOL ok = [timestamp writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
NSDictionary *result;
if (!ok) {
NSLog(@"Error writing file at %@\n%@", filePath, [error localizedFailureReason]);
result = @{
@"status" : @(false)
};
} else {
result = @{
@"status" : @(true)
};
}
callback(@[[NSNull null], result]);
}
@end @end
...@@ -206,6 +206,16 @@ RCT_EXPORT_METHOD(resetUserDefaults:(NSDictionary *)input callback:(RCTResponseS ...@@ -206,6 +206,16 @@ RCT_EXPORT_METHOD(resetUserDefaults:(NSDictionary *)input callback:(RCTResponseS
[self reset_UserDefaultsByKey:input callback:callback]; [self reset_UserDefaultsByKey:input callback:callback];
} }
RCT_EXPORT_METHOD(getLastTimestamp:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self get_TimestampByKey:input callback:callback];
}
RCT_EXPORT_METHOD(setTimestamp:(NSDictionary *)input callback:(RCTResponseSenderBlock)callback)
{
[self set_TimestampByKey:input callback:callback];
}
- (void)isHealthKitAvailable:(RCTResponseSenderBlock)callback - (void)isHealthKitAvailable:(RCTResponseSenderBlock)callback
{ {
BOOL isAvailable = NO; BOOL isAvailable = NO;
......
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