İlk commit: Stepstead Godot istemci (4.6 Mobile)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
commit
6a1706051d
346 changed files with 14415 additions and 0 deletions
85
native/pedometer-ios/pedometer.mm
Normal file
85
native/pedometer-ios/pedometer.mm
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
// Stepstead — iOS Pedometer plugin (CMPedometer) implementasyonu.
|
||||
#import "pedometer.h"
|
||||
|
||||
#import <CoreMotion/CoreMotion.h>
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// Objective-C tarafı: CMPedometer'ı tutar, adım sayısını günceller.
|
||||
@interface StepsteadPedometer : NSObject
|
||||
@property(nonatomic, strong) CMPedometer *pedometer;
|
||||
@property(nonatomic, assign) int stepCount;
|
||||
@property(nonatomic, strong) NSDate *sessionStart;
|
||||
@property(nonatomic, assign) BOOL running;
|
||||
@end
|
||||
|
||||
@implementation StepsteadPedometer
|
||||
@end
|
||||
|
||||
static StepsteadPedometer *_ped = nil;
|
||||
|
||||
Pedometer *Pedometer::instance = nullptr;
|
||||
|
||||
void Pedometer::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("is_available"), &Pedometer::is_available);
|
||||
ClassDB::bind_method(D_METHOD("start"), &Pedometer::start);
|
||||
ClassDB::bind_method(D_METHOD("stop"), &Pedometer::stop);
|
||||
ClassDB::bind_method(D_METHOD("get_step_count"), &Pedometer::get_step_count);
|
||||
}
|
||||
|
||||
bool Pedometer::is_available() {
|
||||
// Not: iOS Simulator'da daima false döner — gerçek cihaz gerekir.
|
||||
return [CMPedometer isStepCountingAvailable] ? true : false;
|
||||
}
|
||||
|
||||
void Pedometer::start() {
|
||||
if (![CMPedometer isStepCountingAvailable]) {
|
||||
return;
|
||||
}
|
||||
if (_ped == nil) {
|
||||
_ped = [[StepsteadPedometer alloc] init];
|
||||
_ped.pedometer = [[CMPedometer alloc] init];
|
||||
_ped.stepCount = 0;
|
||||
}
|
||||
if (_ped.running) {
|
||||
return;
|
||||
}
|
||||
_ped.running = YES;
|
||||
_ped.sessionStart = [NSDate date];
|
||||
_ped.stepCount = 0;
|
||||
|
||||
// Uygulama açıkken canlı güncelleme. numberOfSteps = sessionStart'tan beri.
|
||||
[_ped.pedometer startPedometerUpdatesFromDate:_ped.sessionStart
|
||||
withHandler:^(CMPedometerData *_Nullable data, NSError *_Nullable error) {
|
||||
if (data != nil && error == nil) {
|
||||
_ped.stepCount = [data.numberOfSteps intValue];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
void Pedometer::stop() {
|
||||
if (_ped != nil && _ped.running) {
|
||||
[_ped.pedometer stopPedometerUpdates];
|
||||
_ped.running = NO;
|
||||
}
|
||||
}
|
||||
|
||||
int Pedometer::get_step_count() {
|
||||
return _ped != nil ? _ped.stepCount : 0;
|
||||
}
|
||||
|
||||
Pedometer *Pedometer::get_singleton() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
Pedometer::Pedometer() {
|
||||
ERR_FAIL_COND(instance != nullptr);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
Pedometer::~Pedometer() {
|
||||
if (_ped != nil) {
|
||||
[_ped.pedometer stopPedometerUpdates];
|
||||
_ped = nil;
|
||||
}
|
||||
instance = nullptr;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue