diff --git a/src/Platform_Posix.c b/src/Platform_Posix.c index b3a20d8d9..12516d637 100644 --- a/src/Platform_Posix.c +++ b/src/Platform_Posix.c @@ -143,9 +143,13 @@ cc_uint64 Stopwatch_Measure(void) { /*########################################################################################################################* *-----------------------------------------------------Directory/File------------------------------------------------------* *#########################################################################################################################*/ +#if defined CC_BUILD_IOS +/* implemented in interop_ios.m */ +#else void Directory_GetCachePath(cc_string* path, const char* folder) { String_AppendConst(path, folder); } +#endif cc_result Directory_Create(const cc_string* path) { char str[NATIVE_STR_LEN]; diff --git a/src/interop_ios.m b/src/interop_ios.m index d44a0aa99..b0081383d 100644 --- a/src/interop_ios.m +++ b/src/interop_ios.m @@ -709,7 +709,7 @@ int Platform_GetCommandLineArgs(int argc, STRING_REF char** argv, cc_string* arg cc_result Platform_SetDefaultCurrentDirectory(int argc, char **argv) { // https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html - NSArray* array = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); + NSArray* array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); if (array.count <= 0) return ERR_NOT_SUPPORTED; NSString* str = [array objectAtIndex:0]; @@ -743,6 +743,22 @@ void GetDeviceUUID(cc_string* str) { String_AppendUtf8(str, src, String_Length(src)); } +void Directory_GetCachePath(cc_string* path, const char* folder) { + NSArray* array = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); + if (array.count > 0) { + // try to use iOS app cache folder if possible + // https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html + NSString* str = [array objectAtIndex:0]; + const char* utf8 = [str UTF8String]; + + String_AppendUtf8(path, utf8, String_Length(utf8)); + String_Format1(path, "/%c", folder); + Directory_Create(path); + } else { + String_AppendConst(path, folder); + } +} + /*########################################################################################################################* *-----------------------------------------------------Font handling-------------------------------------------------------*