Skip to content

Commit ebe2cf0

Browse files
sandyklarkhassankhan
authored andcommitted
fix(maccatalyst): use the correct migrations path on the Mac Catalyst platform
Fixes prisma#10 for Mac Catalyst platform, its likely the same fix will work for macOS in the future too. Also fixes an issue when using `NSURL.absoluteString` on a path contains spaces, the spaces would get replaced by `%20`.
1 parent a2f22b1 commit ebe2cf0

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

ios/Prisma.mm

+33-7
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,54 @@ @implementation Prisma
1616
if (cxxBridge == nil) {
1717
return @false;
1818
}
19-
19+
2020
auto jsiRuntime = (facebook::jsi::Runtime *)cxxBridge.runtime;
2121
if (jsiRuntime == nil) {
2222
return @false;
2323
}
2424
auto &runtime = *jsiRuntime;
2525
auto callInvoker = _bridge.jsCallInvoker;
26-
26+
2727
// get migrations folder
28-
auto bundleURL = NSBundle.mainBundle.bundleURL;
29-
auto migrations_path_absolute = [NSString stringWithFormat:@"%@%@", bundleURL.absoluteString, @"migrations"];
28+
NSURL *bundleURL = NSBundle.mainBundle.bundleURL;
29+
#if TARGET_OS_MACCATALYST
30+
NSString *migrations_path_absolute = [bundleURL.path stringByAppendingPathComponent:@"Contents/Resources/migrations"];
31+
NSString *identifier = [[NSBundle mainBundle] bundleIdentifier];
32+
33+
// @TODO Add better error handling and reporting
34+
NSURL *applicationSupport = [[NSFileManager defaultManager] URLForDirectory: NSApplicationSupportDirectory
35+
inDomain: NSUserDomainMask
36+
appropriateForURL: nil
37+
create: YES
38+
error: nil];
39+
40+
NSString *libraryPathAbsolute = [applicationSupport.path stringByAppendingPathComponent:identifier];
41+
NSString *libraryPath = [libraryPathAbsolute stringByReplacingOccurrencesOfString:@"file://" withString:@""];
42+
// @TODO Add better error handling and reporting
43+
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath: libraryPath
44+
withIntermediateDirectories: YES
45+
attributes: nil
46+
error: nil];
47+
48+
if (!success) {
49+
NSLog(@"Failed to create folder at %@", libraryPath);
50+
}
51+
#else
52+
NSString *migrations_path_absolute = [bundleURL.path stringByAppendingPathComponent:@"migrations"];
53+
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, true);
54+
NSString *libraryPath = [paths objectAtIndex:0];
55+
#endif
3056
auto migrations_path = [migrations_path_absolute stringByReplacingOccurrencesOfString:@"file://" withString:@""];
31-
57+
3258
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, true);
3359
NSString *libraryPath = [paths objectAtIndex:0];
34-
60+
3561
#if DEBUG
3662
std::cout << "▲ NSHomeDirectory:\n" << [NSHomeDirectory() UTF8String] << std::endl;
3763
std::cout << "▲ Library Path:\n" << [libraryPath UTF8String] << std::endl;
3864
std::cout << "▲ Migrations Path:\n" << [migrations_path UTF8String] << std::endl;
3965
#endif
40-
66+
4167
prisma::install_cxx(runtime, callInvoker, [libraryPath UTF8String], [migrations_path UTF8String]);
4268
return nil;
4369
}

0 commit comments

Comments
 (0)