mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

Breaking change: removed deprecated methods of PlatformMessages, leaving only binary messaging there. All other use of platform communication now goes through PlatformMessageChannel and PlatformMethodChannels. Retained use of String and JSON codecs for now. Companion engine PR: flutter/engine#3482
39 lines
1.4 KiB
Objective-C
39 lines
1.4 KiB
Objective-C
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
#import <Flutter/Flutter.h>
|
|
#import <CoreLocation/CoreLocation.h>
|
|
|
|
@implementation AppDelegate {
|
|
CLLocationManager* _locationManager;
|
|
}
|
|
- (BOOL)application:(UIApplication*)application
|
|
didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
|
|
FlutterViewController* controller =
|
|
(FlutterViewController*)self.window.rootViewController;
|
|
FlutterMethodChannel* locationChannel = [FlutterMethodChannel
|
|
methodChannelNamed:@"location"
|
|
binaryMessenger:controller
|
|
codec:[FlutterStandardMethodCodec sharedInstance]];
|
|
[locationChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResultReceiver result) {
|
|
if ([@"getLocation" isEqualToString:call.method]) {
|
|
if (_locationManager == nil) {
|
|
_locationManager = [[CLLocationManager alloc] init];
|
|
[_locationManager startMonitoringSignificantLocationChanges];
|
|
}
|
|
CLLocation* location = _locationManager.location;
|
|
result(@[@(location.coordinate.latitude), @(location.coordinate.longitude)], nil);
|
|
} else {
|
|
result(nil, [FlutterError errorWithCode:@"unknown method"
|
|
message:@"Unknown location method called"
|
|
details:nil]);
|
|
}
|
|
}];
|
|
return YES;
|
|
}
|
|
|
|
@end
|