ios: Implement getBaseDirectory in the platform-channel

This is one of the many platform-channels that needs to be implemented
for ios. We may as well get started.
This commit is contained in:
Vishesh Handa
2019-05-17 17:54:46 +02:00
parent 071f9962ba
commit cb9cc3b1a7

View File

@ -1,12 +1,46 @@
#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
NSString* GetDirectoryOfType(NSSearchPathDirectory dir) {
NSArray* paths = NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES);
return paths.firstObject;
}
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
FlutterViewController* controller = (FlutterViewController*)self.window.rootViewController;
FlutterMethodChannel* gitChannel = [FlutterMethodChannel
methodChannelWithName:@"gitjournal.io/git" binaryMessenger:controller];
[gitChannel setMethodCallHandler:^(FlutterMethodCall* call, FlutterResult result) {
NSString* filesDir = [self getApplicationDocumentsDirectory];
if ([@"getBaseDirectory" isEqualToString:call.method]) {
/*
int batteryLevel = [weakSelf getBatteryLevel];
if (batteryLevel == -1) {
result([FlutterError errorWithCode:@"UNAVAILABLE"
message:@"Battery info unavailable"
details:nil]);
} else {
result(@(batteryLevel));
}
*/
result(filesDir);
} else {
result(FlutterMethodNotImplemented);
}
}];
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (NSString*)getApplicationDocumentsDirectory {
return GetDirectoryOfType(NSDocumentDirectory);
}
@end