1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-13 00:08:24 +00:00

Add experimental/pedometer (#1587)

* Add `experimental/pedometer`

* Fixup for linter warnings

* Update CI config
This commit is contained in:
Brett Morgan
2023-01-24 11:31:12 +11:00
committed by GitHub
parent 3bc6ad8110
commit 70f3daa9f7
109 changed files with 98007 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
#import "pedometerHelper.h"
#import <CoreMotion/CoreMotion.h>
#import <CoreMotion/CMPedometer.h>
#import <Foundation/Foundation.h>
#import <Foundation/NSDate.h>
#include "dart-sdk/include/dart_api_dl.h"
// Need to import the dart headers to get the definitions Dart_CObject
#include "dart-sdk/include/dart_api_dl.h"
// Helper function that takes a pointer to CMPedometer data and converts it to a Dart C Object
static Dart_CObject NSObjectToCObject(CMPedometerData* n) {
Dart_CObject cobj;
cobj.type = Dart_CObject_kInt64;
cobj.value.as_int64 = (int64_t) n;
return cobj;
}
@implementation PedometerHelper
+(void)startPedometerWithPort: (Dart_Port) sendPort pedometer: (CMPedometer*) pedometer start: (NSDate*) start end: (NSDate*) end {
// Start the pedometer
[pedometer queryPedometerDataFromDate:start toDate:end withHandler:^(CMPedometerData *pedometerData, NSError *error) {
if(error == nil){
pedometerData = [pedometerData retain];
Dart_CObject data = NSObjectToCObject(pedometerData);
const bool success = Dart_PostCObject_DL(sendPort, &data);
NSAssert(success, @"Couldn't send to Dart@");
}
else{
NSLog(@"Error:%@", error);
}
}];
}
@end