Commit 002ba64b authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Migrate platform_channel to updated API (#9094)

See flutter/engine#3539
parent e7f13616
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
FlutterViewController* controller = FlutterViewController* controller =
(FlutterViewController*)self.window.rootViewController; (FlutterViewController*)self.window.rootViewController;
FlutterMethodChannel* batteryChannel = [FlutterMethodChannel FlutterMethodChannel* batteryChannel = [FlutterMethodChannel
methodChannelNamed:@"battery" methodChannelWithName:@"battery"
binaryMessenger:controller binaryMessenger:controller
codec:[FlutterStandardMethodCodec sharedInstance]]; codec:[FlutterStandardMethodCodec sharedInstance]];
[batteryChannel setMethodCallHandler:^(FlutterMethodCall* call, [batteryChannel setMethodCallHandler:^(FlutterMethodCall* call,
...@@ -21,16 +21,16 @@ ...@@ -21,16 +21,16 @@
UIDevice* device = UIDevice.currentDevice; UIDevice* device = UIDevice.currentDevice;
device.batteryMonitoringEnabled = YES; device.batteryMonitoringEnabled = YES;
if (device.batteryState == UIDeviceBatteryStateUnknown) { if (device.batteryState == UIDeviceBatteryStateUnknown) {
result(nil, [FlutterError errorWithCode:@"UNAVAILABLE" result([FlutterError errorWithCode:@"UNAVAILABLE"
message:@"Battery info unavailable" message:@"Battery info unavailable"
details:nil]); details:nil]);
} else { } else {
result([NSNumber numberWithInt:(int)(device.batteryLevel * 100)], nil); result([NSNumber numberWithInt:(int)(device.batteryLevel * 100)]);
} }
} else { } else {
result(nil, [FlutterError errorWithCode:@"UNKNOWN_METHOD" result([FlutterError errorWithCode:@"UNKNOWN_METHOD"
message:@"Unknown battery method called" message:@"Unknown battery method called"
details:nil]); details:nil]);
} }
}]; }];
return YES; return YES;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment