From b07df91aa0063b6bc53bf855125a9d023a1e7aa2 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Mon, 20 May 2019 20:32:26 +0200 Subject: [PATCH] ios: Allow the app to be run * Implemented a fake gitInit which just created the folder for now * AndroidDeviceInfo doesn't exist on ios --- ios/Runner/AppDelegate.m | 38 +++++++++++++++++++++++++------------- lib/app.dart | 14 +++++++++----- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/ios/Runner/AppDelegate.m b/ios/Runner/AppDelegate.m index 0fd40440..5b5ec425 100644 --- a/ios/Runner/AppDelegate.m +++ b/ios/Runner/AppDelegate.m @@ -15,21 +15,33 @@ NSString* GetDirectoryOfType(NSSearchPathDirectory dir) { 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]; + NSString *method = [call method]; + NSDictionary *arguments = [call arguments]; - if (batteryLevel == -1) { - result([FlutterError errorWithCode:@"UNAVAILABLE" - message:@"Battery info unavailable" - details:nil]); - } else { - result(@(batteryLevel)); - } - */ + NSString* filesDir = [self getApplicationDocumentsDirectory]; + if ([@"getBaseDirectory" isEqualToString:method]) { result(filesDir); - } else { + } + else if ([@"gitInit" isEqualToString:method]) { + NSString *folderName = arguments[@"folderName"]; + NSArray *components = [NSArray arrayWithObjects:filesDir, folderName, nil]; + NSString* dirPath = [NSString pathWithComponents:components]; + + NSError *error; + if (![[NSFileManager defaultManager] createDirectoryAtPath:dirPath + withIntermediateDirectories:NO + attributes:nil + error:&error]) + { + NSLog(@"Create directory error: %@", error); + result([FlutterError errorWithCode:@"FAILED" + message:@"Failed to perform fake gitInit" details:nil]); + } + else { + result(@YES); + } + } + else { result(FlutterMethodNotImplemented); } }]; diff --git a/lib/app.dart b/lib/app.dart index 1eb36aa3..e28375f5 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -30,11 +30,15 @@ class JournalApp extends StatelessWidget { // Check if in debugMode or not a real device // assert(JournalApp.isInDebugMode = true); - DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); - AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; - if (androidInfo.isPhysicalDevice == false) { - print("Not running in a physcial device"); - JournalApp.isInDebugMode = true; + try { + DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); + AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; + if (androidInfo.isPhysicalDevice == false) { + print("Not running in a physcial device"); + JournalApp.isInDebugMode = true; + } + } catch (e) { + print(e); } if (JournalApp.isInDebugMode) {