changeset 2445:a773008c7c5d

iOS: Make sure the plain text UTI is used with filePicker. Also strip off the "file://" prefixing the file path returned.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 09 Apr 2021 11:05:51 +0000
parents ba24ddb19a43
children b9d373d1ccf5
files dwtest.c ios/dw.m
diffstat 2 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/dwtest.c	Fri Apr 09 10:01:22 2021 +0000
+++ b/dwtest.c	Fri Apr 09 11:05:51 2021 +0000
@@ -290,16 +290,16 @@
     return TRUE;
 }
 
-void read_file( void )
+void read_file(void)
 {
     int i,len;
     fp = fopen(current_file, "r" );
     if(fp)
     {
-       lp = (char **)calloc( 1000,sizeof(char *));
+       lp = (char **)calloc(1000,sizeof(char *));
        /* should test for out of memory */
        max_linewidth=0;
-       for(i = 0; i < 1000; i++)
+       for(i=0; i<1000; i++)
        {
            lp[i] = (char *)calloc(1, 1025);
            if (fgets( lp[i], 1024, fp ) == NULL)
--- a/ios/dw.m	Fri Apr 09 10:01:22 2021 +0000
+++ b/ios/dw.m	Fri Apr 09 11:05:51 2021 +0000
@@ -977,7 +977,18 @@
     char *file = NULL;
 
     if(url && [[url absoluteString] length] > 0)
-        file = strdup([[url absoluteString] UTF8String]);
+    {
+        const char *tmp = [[url absoluteString] UTF8String];
+
+        if(tmp)
+        {
+            /* Strip off file:// so it looks the same as other platforms */
+            if(strncmp(tmp, "file://", 7) == 0)
+                file = strdup(&tmp[7]);
+            else
+                file = strdup(tmp);
+        }
+    }
     dw_dialog_dismiss(dialog, file);
 }
 -(void)documentPickerWasCancelled:(UIDocumentPickerViewController *)controller
@@ -1090,7 +1101,7 @@
         mode = UIDocumentPickerModeExportToService;
     /* Try to generate a UTI for our passed extension */
     if(ext)
-        UTIs = [NSArray arrayWithObject:[NSString stringWithFormat:@"public.%s", ext]];
+        UTIs = [NSArray arrayWithObjects:[NSString stringWithFormat:@"public.%s", ext], @"public.text", nil];
     else
         UTIs = @[@"public.text"];
     picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:UTIs inMode:mode];