Platform channel API cleanup (#9048)
This commit is contained in:
committed by
GitHub
parent
0e43e581d1
commit
471c97df30
@@ -37,9 +37,12 @@ public class MainActivity extends FlutterActivity {
|
||||
} else {
|
||||
response.error("UNAVAILABLE", "Battery level not available.", null);
|
||||
}
|
||||
} else {
|
||||
response.notImplemented();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private int getBatteryLevel() {
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
(FlutterViewController*)self.window.rootViewController;
|
||||
FlutterMethodChannel* batteryChannel = [FlutterMethodChannel
|
||||
methodChannelWithName:@"battery"
|
||||
binaryMessenger:controller
|
||||
codec:[FlutterStandardMethodCodec sharedInstance]];
|
||||
binaryMessenger:controller];
|
||||
[batteryChannel setMethodCallHandler:^(FlutterMethodCall* call,
|
||||
FlutterResultReceiver result) {
|
||||
if ([@"getBatteryLevel" isEqualToString:call.method]) {
|
||||
@@ -25,15 +24,12 @@
|
||||
message:@"Battery info unavailable"
|
||||
details:nil]);
|
||||
} else {
|
||||
result([NSNumber numberWithInt:(int)(device.batteryLevel * 100)]);
|
||||
result(@((int)(device.batteryLevel * 100)));
|
||||
}
|
||||
} else {
|
||||
result([FlutterError errorWithCode:@"UNKNOWN_METHOD"
|
||||
message:@"Unknown battery method called"
|
||||
details:nil]);
|
||||
result(FlutterMethodNotImplemented);
|
||||
}
|
||||
}];
|
||||
return YES;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user