core_location_fluttify

This commit is contained in:
2024-11-17 16:00:52 +08:00
commit 52cf298ec1
93 changed files with 2349 additions and 0 deletions

View File

@ -0,0 +1,13 @@
//
// Created by Yohom Bao on 2019/11/22.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import "CoreLocationFluttifyPlugin.h"
NS_ASSUME_NONNULL_BEGIN
void CLFloorHandler(NSString *method, id args, FlutterResult methodResult);
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,28 @@
//
// Created by Yohom Bao on 2019/11/22.
//
#import <CoreLocation/CoreLocation.h>
#import "CLFloorHandler.h"
extern NSMutableDictionary<NSString *, NSObject *> *STACK;
extern NSMutableDictionary<NSNumber *, NSObject *> *HEAP;
extern BOOL enableLog;
void CLFloorHandler(NSString *method, id rawArgs, FlutterResult methodResult) {
// CLFloorlevel
if ([@"CLFloor::get_level" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLFloor *__this__ = (CLFloor *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
methodResult(@(__this__.level));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else {
methodResult(FlutterMethodNotImplemented);
}
}

View File

@ -0,0 +1,15 @@
//
// CLHeadingHandler.h
// foundation_fluttify
//
// Created by Yohom Bao on 2019/12/11.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
void CLHeadingHandler(NSString* method, id args, FlutterResult methodResult);
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,60 @@
//
// CLHeadingHandler.m
// foundation_fluttify
//
// Created by Yohom Bao on 2019/12/11.
//
#import "CLHeadingHandler.h"
#import <CoreLocation/CoreLocation.h>
extern NSMutableDictionary<NSString *, NSObject *> *STACK;
extern NSMutableDictionary<NSNumber *, NSObject *> *HEAP;
extern BOOL enableLog;
void CLHeadingHandler(NSString *method, id rawArgs, FlutterResult methodResult) {
if ([@"CLHeading::getMagneticHeading" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLHeading *__this__ = (CLHeading *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
CLLocationDirection magneticHeading = [__this__ magneticHeading];
methodResult(@(magneticHeading));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
}
if ([@"CLHeading::getTrueHeading" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLHeading *__this__ = (CLHeading *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
CLLocationDirection trueHeading = [__this__ trueHeading];
methodResult(@(trueHeading));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
}
if ([@"CLHeading::getHeadingAccuracy" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLHeading *__this__ = (CLHeading *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
CLLocationDirection headingAccuracy = [__this__ headingAccuracy];
methodResult(@(headingAccuracy));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else {
methodResult(FlutterMethodNotImplemented);
}
}

View File

@ -0,0 +1,12 @@
//
// Created by Yohom Bao on 2019/11/22.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
void CLLocationCoordinate2DHandler(NSString* method, id args, FlutterResult methodResult);
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,101 @@
//
// Created by Yohom Bao on 2019/11/22.
//
#import <CoreLocation/CoreLocation.h>
#import "CLLocationCoordinate2DHandler.h"
extern NSMutableDictionary<NSString *, NSObject *> *STACK;
extern NSMutableDictionary<NSNumber *, NSObject *> *HEAP;
extern BOOL enableLog;
void CLLocationCoordinate2DHandler(NSString *method, id rawArgs, FlutterResult methodResult) {
if ([@"CLLocationCoordinate2D::get_latitude" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
NSValue *dataValue = (NSValue *) args[@"__this__"];
if (dataValue != nil && (NSNull *) dataValue != [NSNull null]) {
CLLocationCoordinate2D _structValue;
[dataValue getValue:&_structValue];
methodResult(@(_structValue.latitude));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else if ([@"CLLocationCoordinate2D::get_longitude" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
NSValue *dataValue = (NSValue *) args[@"__this__"];
if (dataValue != nil && (NSNull *) dataValue != [NSNull null]) {
CLLocationCoordinate2D _structValue;
[dataValue getValue:&_structValue];
methodResult(@(_structValue.longitude));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else if ([@"CLLocationCoordinate2D::get_latitude_batch" isEqualToString:method]) {
NSArray<NSDictionary<NSString *, id> *> *args = (NSArray<NSDictionary<NSString *, id> *> *) rawArgs;
NSMutableArray<NSNumber *> *result = [NSMutableArray arrayWithCapacity:args.count];
for (NSUInteger i = 0; i < args.count; i++) {
NSValue *dataValue = (NSValue *) args[i][@"__this__"];
CLLocationCoordinate2D _structValue;
[dataValue getValue:&_structValue];
[result addObject:@(_structValue.latitude)];
}
methodResult(result);
} else if ([@"CLLocationCoordinate2D::get_longitude_batch" isEqualToString:method]) {
NSArray<NSDictionary<NSString *, id> *> *args = (NSArray<NSDictionary<NSString *, id> *> *) rawArgs;
NSMutableArray<NSNumber *> *result = [NSMutableArray arrayWithCapacity:args.count];
for (NSUInteger i = 0; i < args.count; i++) {
NSValue *dataValue = (NSValue *) args[i][@"__this__"];
CLLocationCoordinate2D _structValue;
[dataValue getValue:&_structValue];
[result addObject:@(_structValue.longitude)];
}
methodResult(result);
} else if ([@"CLLocationCoordinate2D::createCLLocationCoordinate2D" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLLocationDegrees latitude = [args[@"latitude"] doubleValue];
CLLocationDegrees longitude = [args[@"longitude"] doubleValue];
CLLocationCoordinate2D data = CLLocationCoordinate2DMake(latitude, longitude);
NSValue *dataValue = [NSValue value:&data withObjCType:@encode(CLLocationCoordinate2D)];
methodResult(dataValue);
} else if ([@"CLLocationCoordinate2D::create_batchCLLocationCoordinate2D" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
NSArray<NSNumber *> *latitudeBatch = (NSArray<NSNumber *> *) args[@"latitude_batch"];
NSArray<NSNumber *> *longitudeBatch = (NSArray<NSNumber *> *) args[@"longitude_batch"];
NSMutableArray<NSObject *> *resultBatch = [NSMutableArray arrayWithCapacity:latitudeBatch.count];
for (NSUInteger i = 0; i < latitudeBatch.count; i++) {
CLLocationDegrees latitude = [latitudeBatch[i] doubleValue];
CLLocationDegrees longitude = [longitudeBatch[i] doubleValue];
CLLocationCoordinate2D data = CLLocationCoordinate2DMake(latitude, longitude);
NSValue *dataValue = [NSValue value:&data withObjCType:@encode(CLLocationCoordinate2D)];
[resultBatch addObject:dataValue];
}
methodResult(resultBatch);
} else {
methodResult(FlutterMethodNotImplemented);
}
}

View File

@ -0,0 +1,13 @@
//
// Created by Yohom Bao on 2019/11/22.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import "CoreLocationFluttifyPlugin.h"
NS_ASSUME_NONNULL_BEGIN
void CLLocationHandler(NSString* method, id args, FlutterResult methodResult);
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,97 @@
//
// Created by Yohom Bao on 2019/11/22.
//
#import <CoreLocation/CoreLocation.h>
#import "CLLocationHandler.h"
extern NSMutableDictionary<NSString *, NSObject *> *STACK;
extern NSMutableDictionary<NSNumber *, NSObject *> *HEAP;
extern BOOL enableLog;
void CLLocationHandler(NSString *method, id rawArgs, FlutterResult methodResult) {
if ([@"CLLocation::get_coordinate" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLLocation *__this__ = (CLLocation *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
CLLocationCoordinate2D data = __this__.coordinate;
NSValue *dataValue = [NSValue value:&data withObjCType:@encode(CLLocationCoordinate2D)];
methodResult(dataValue);
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else if ([@"CLLocation::get_altitude" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLLocation *__this__ = (CLLocation *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
methodResult(@(__this__.altitude));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else if ([@"CLLocation::get_horizontalAccuracy" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLLocation *__this__ = (CLLocation *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
methodResult(@(__this__.horizontalAccuracy));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else if ([@"CLLocation::get_verticalAccuracy" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLLocation *__this__ = (CLLocation *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
methodResult(@(__this__.verticalAccuracy));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else if ([@"CLLocation::get_course" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLLocation *__this__ = (CLLocation *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
methodResult(@(__this__.course));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else if ([@"CLLocation::get_speed" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLLocation *__this__ = (CLLocation *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
methodResult(@(__this__.speed));
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else if ([@"CLLocation::get_floor" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLLocation *__this__ = (CLLocation *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
CLFloor *floor = __this__.floor;
methodResult(floor);
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else {
methodResult(FlutterMethodNotImplemented);
}
}

View File

@ -0,0 +1,13 @@
//
// Created by Yohom Bao on 2019/11/22.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
#import "CoreLocationFluttifyPlugin.h"
NS_ASSUME_NONNULL_BEGIN
void CLLocationManagerHandler(NSString* method, id args, FlutterResult methodResult);
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,41 @@
//
// Created by Yohom Bao on 2019/11/22.
//
#import <CoreLocation/CoreLocation.h>
#import "CLLocationManagerHandler.h"
extern NSMutableDictionary<NSNumber *, NSObject *> *HEAP;
extern BOOL enableLog;
void CLLocationManagerHandler(NSString *method, id rawArgs, FlutterResult methodResult) {
if ([@"CLLocationManager::requestAlwaysAuthorization" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLLocationManager *__this__ = (CLLocationManager *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
[__this__ requestAlwaysAuthorization];
methodResult(@"success");
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
}
else if ([@"CLLocationManager::requestWhenInUseAuthorization" isEqualToString:method]) {
NSDictionary<NSString *, id> *args = (NSDictionary<NSString *, id> *) rawArgs;
CLLocationManager *__this__ = (CLLocationManager *) args[@"__this__"];
if (__this__ != nil && (NSNull *) __this__ != [NSNull null]) {
[__this__ requestWhenInUseAuthorization];
methodResult(@"success");
} else {
methodResult([FlutterError errorWithCode:@"目标对象为null"
message:@"目标对象为null"
details:@"目标对象为null"]);
}
} else {
methodResult(FlutterMethodNotImplemented);
}
}

View File

@ -0,0 +1,5 @@
#import <Flutter/Flutter.h>
@interface CoreLocationFluttifyPlugin : NSObject<FlutterPlugin>
- (instancetype) initWithRegistrar:(NSObject<FlutterPluginRegistrar>*) registrar;
@end

View File

@ -0,0 +1,55 @@
#import "CoreLocationFluttifyPlugin.h"
#import "CLLocationCoordinate2DHandler.h"
#import "CLLocationHandler.h"
#import "CLFloorHandler.h"
#import "CLLocationManagerHandler.h"
#import "CLHeadingHandler.h"
#import "FluttifyMessageCodec.h"
// Container for Dart side random access objects
extern NSMutableDictionary<NSNumber *, NSObject *> *HEAP;
// whether enable log or not
extern BOOL enableLog;
@implementation CoreLocationFluttifyPlugin {
NSObject <FlutterPluginRegistrar> *_registrar;
}
+ (void)registerWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
NSString* _channelName = @"com.fluttify/core_location_method";
FlutterMethodChannel *channel = [FlutterMethodChannel
methodChannelWithName:_channelName
binaryMessenger:[registrar messenger]
codec:[FlutterStandardMethodCodec codecWithReaderWriter:[[FluttifyReaderWriter alloc] init]]];
CoreLocationFluttifyPlugin *instance = [[CoreLocationFluttifyPlugin alloc] initWithRegistrar:registrar];
[registrar addMethodCallDelegate:instance channel:channel];
}
- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
self = [super init];
if (self) {
_registrar = registrar;
}
return self;
}
- (void)handleMethodCall:(FlutterMethodCall *)methodCall result:(FlutterResult)methodResult {
id rawArgs = [methodCall arguments];
if ([methodCall.method hasPrefix:@"CLLocationCoordinate2D"]) {
CLLocationCoordinate2DHandler(methodCall.method, rawArgs, methodResult);
} else if ([methodCall.method hasPrefix:@"CLLocation"]) {
CLLocationHandler(methodCall.method, rawArgs, methodResult);
} else if ([methodCall.method hasPrefix:@"CLFloor"]) {
CLFloorHandler(methodCall.method, rawArgs, methodResult);
} else if ([methodCall.method hasPrefix:@"CLLocationManager"]) {
CLLocationManagerHandler(methodCall.method, rawArgs, methodResult);
} else if ([methodCall.method hasPrefix:@"CLHeadingHandler"]) {
CLHeadingHandler(methodCall.method, rawArgs, methodResult);
} else {
methodResult(FlutterMethodNotImplemented);
}
}
@end