mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-07-03 14:06:51 +08:00
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:
@ -1,12 +1,46 @@
|
|||||||
#include "AppDelegate.h"
|
#include "AppDelegate.h"
|
||||||
#include "GeneratedPluginRegistrant.h"
|
#include "GeneratedPluginRegistrant.h"
|
||||||
|
|
||||||
|
NSString* GetDirectoryOfType(NSSearchPathDirectory dir) {
|
||||||
|
NSArray* paths = NSSearchPathForDirectoriesInDomains(dir, NSUserDomainMask, YES);
|
||||||
|
return paths.firstObject;
|
||||||
|
}
|
||||||
|
|
||||||
@implementation AppDelegate
|
@implementation AppDelegate
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
- (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];
|
[GeneratedPluginRegistrant registerWithRegistry:self];
|
||||||
// Override point for customization after application launch.
|
// Override point for customization after application launch.
|
||||||
return [super application:application didFinishLaunchingWithOptions:launchOptions];
|
return [super application:application didFinishLaunchingWithOptions:launchOptions];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSString*)getApplicationDocumentsDirectory {
|
||||||
|
return GetDirectoryOfType(NSDocumentDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
Reference in New Issue
Block a user