From cb9cc3b1a70c759d2e54f14c0e5c7d5536ce755b Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Fri, 17 May 2019 17:54:46 +0200 Subject: [PATCH] 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. --- ios/Runner/AppDelegate.m | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/ios/Runner/AppDelegate.m b/ios/Runner/AppDelegate.m index 112becd1..0fd40440 100644 --- a/ios/Runner/AppDelegate.m +++ b/ios/Runner/AppDelegate.m @@ -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 { - [GeneratedPluginRegistrant registerWithRegistry:self]; - // Override point for customization after application launch. - return [super application:application didFinishLaunchingWithOptions: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