Skip to content

Commit 0c5bafd

Browse files
authored
fix: Create the application support directory if it does not already exist (#815)
1 parent e38ed22 commit 0c5bafd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

ios/Classes/DBManager.m

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,20 @@ @implementation DBManager
2727
-(instancetype)initWithDatabaseFilePath:(NSString *)dbFilePath{
2828
self = [super init];
2929
if (self) {
30-
self.appDirectory = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) firstObject];
30+
// Get application support directory.
31+
// Create the directory if it does not already exist.
32+
NSError *error;
33+
NSURL *appDirectoryUrl = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory
34+
inDomain:NSUserDomainMask
35+
appropriateForURL:nil
36+
create:YES
37+
error:&error];
38+
self.appDirectory = appDirectoryUrl.path;
39+
if (debug) {
40+
if (error) {
41+
NSLog(@"Get application support directory error: %@", error);
42+
}
43+
}
3144

3245
// Keep the database filepath
3346
self.databaseFilePath = dbFilePath;

0 commit comments

Comments
 (0)