changeset 2787:56312f9c1d6c

iOS: Return the Application Sandbox's Documents folder from dw_user_dir() instead of the home directory by default. May not have write permission in the actual home directory, causing errors saving configuration files. Fall back to the application sandbox folder or / if everything fails.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 13 Jul 2022 05:20:31 +0000
parents 3934ac8b394c
children 8a4f162810c2
files ios/dw.m
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ios/dw.m	Wed Jul 13 04:51:09 2022 +0000
+++ b/ios/dw.m	Wed Jul 13 05:20:31 2022 +0000
@@ -4028,9 +4028,14 @@
 
     if(!_user_dir[0])
     {
-        char *home = getenv("HOME");
-
-        if(home)
+        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
+                                                             NSUserDomainMask, YES);
+        NSString *nshome = [paths firstObject];
+        const char *home;
+
+        if(nshome && (home = [nshome UTF8String]))
+            strncpy(_user_dir, home, PATH_MAX);
+        else if((nshome = NSHomeDirectory()) && (home = [nshome UTF8String]))
             strncpy(_user_dir, home, PATH_MAX);
         else
             strcpy(_user_dir, "/");