ios – Can’t get location from swift to flutter utilizing customized platform-specific code

0
89


I’ve to get location of iOS gadget, however I’m not utilizing flutter packages. I must get it from swift code and cross it to flutter.

I haven’t got any expertise in swift. I’ve used the next code but. Can somebody please assist.

import UIKit
import Flutter
import CoreLocation

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
    override func utility(
        _ utility: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
        let testChannel = FlutterMethodChannel(title: "com.instance.testFlutter/check",
                                               binaryMessenger: controller.binaryMessenger)
        testChannel.setMethodCallHandler({
            [weak self] (name: FlutterMethodCall, end result: @escaping FlutterResult) -> Void in
            // This technique is invoked on the UI thread.
            if name.technique == "getLocation"{
                self?.getLocation(end result: end result)
            }
            else{
                end result(FlutterMethodNotImplemented)
                return
            }
        })
        
        
        
        
        GeneratedPluginRegistrant.register(with: self)
        return tremendous.utility(utility, didFinishLaunchingWithOptions: launchOptions)
    }
    
    non-public func getLocation(end result: FlutterResult){
        var locationManager: CLLocationManager?
        locationManager?.requestAlwaysAuthorization()
        if CLLocationManager.locationServicesEnabled() {
            locationManager?.startUpdatingLocation()
            end result("updating location")
        }
        
        
        
    }
    func locationManager(_ supervisor: CLLocationManager, didUpdateLocations areas: [CLLocation], end result: FlutterResult) {
        end result("testing")
        guard let locValue: CLLocationCoordinate2D = supervisor.location?.coordinate else { return }
        end result("location = (locValue.latitude) (locValue.longitude)")
    }
}