Objective C implementation refactored
MODIFY
geolocator/example/ios/Runner.xcworkspace/contents.xcworkspacedata
geolocator/example/ios/Runner.xcworkspace/contents.xcworkspacedata
<Workspace
version = "1.0">
<FileRef
- location = "group:build">
- </FileRef>
- <FileRef
- location = "group:Flutter">
- </FileRef>
- <FileRef
- location = "group:Podfile">
- </FileRef>
- <FileRef
- location = "group:Podfile.lock">
- </FileRef>
- <FileRef
- location = "group:Pods">
- </FileRef>
- <FileRef
- location = "group:Runner">
+ location = "group:Runner.xcodeproj">
</FileRef>
<FileRef
- location = "group:Runner.xcodeproj">
+ location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

MODIFY
geolocator/ios/Classes/GeolocatorPlugin.m
geolocator/ios/Classes/GeolocatorPlugin.m
eventChannelWithName:@"flutter.baseflow.com/geolocator_updates"
binaryMessenger:registrar.messenger];
+ FlutterEventChannel *locationServiceUpdatesEventChannel = [FlutterEventChannel eventChannelWithName:@"flutter.baseflow.com/geolocator_service_updates" binaryMessenger:registrar.messenger];
+
+
GeolocatorPlugin *instance = [[GeolocatorPlugin alloc] init];
[registrar addMethodCallDelegate:instance channel:methodChannel];
PositionStreamHandler *positionStreamHandler = [[PositionStreamHandler alloc] initWithGeolocationHandler:instance.geolocationHandler
PermissionHandler:instance.permissionHandler];
+
+ LocationServiceStreamHandler *locationServiceStreamHandler = [[LocationServiceStreamHandler alloc]];
[positionUpdatesEventChannel setStreamHandler:positionStreamHandler];
}

ADD
geolocator/ios/Classes/Handlers/LocationServiceStreamHandler.h
+//
+// LocationServiceStreamHandler.h
+// Pods
+//
+// Created by Floris Smit on 10/06/2021.
+//
+
+#ifndef LocationServiceStreamHandler_h
+#define LocationServiceStreamHandler_h
+
+#import <Flutter/Flutter.h>
+
+@interface LocationServiceStreamHandler : NSObject<FlutterStreamHandler, CLLocationManagerDelegate>
+
+@end
+
+
+#endif /* LocationServiceStreamHandler_h */

ADD
geolocator/ios/Classes/Handlers/LocationServiceStreamHandler.m
+//
+// LocationServiceHandler.m
+// geolocator
+//
+// Created by Floris Smit on 10/06/2021.
+//
+
+#import <Foundation/Foundation.h>
+#import <Flutter/Flutter.h>
+#import <CoreLocation/CoreLocation.h>
+#import "LocationServiceStreamHandler.h"
+#import "ServiceStatus.h"
+
+@interface LocationServiceStreamHandler()
+@property (strong, nonatomic) CLLocationManager *locationManager;
+@end
+
+@implementation LocationServiceStreamHandler {
+
+FlutterEventSink _eventSink;
+
+}
+
+- (FlutterError * _Nullable)onCancelWithArguments:(id _Nullable)arguments {
+ self.locationManager = nil;
+ _eventSink = nil;
+ return nil;
+}
+
+- (FlutterError * _Nullable)onListenWithArguments:(id _Nullable)arguments eventSink:(nonnull FlutterEventSink)events {
+ _eventSink = events;
+ if(self.locationManager == nil){
+ self.locationManager = [[CLLocationManager alloc] init];
+ self.locationManager.delegate = self;
+ }
+ return nil;
+}
+
+- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
+ if([CLLocationManager locationServicesEnabled]){
+ _eventSink([NSNumber numberWithInt:(ServiceStatus)enabled]);
+ }else{
+ _eventSink([NSNumber numberWithInt:(ServiceStatus)disabled]);
+ }
+}
+
+@end

Objective C implementation refactored