{"id":429,"date":"2011-07-06T12:49:21","date_gmt":"2011-07-06T12:49:21","guid":{"rendered":"https:\/\/blog.alwawee.ru\/?p=429"},"modified":"2011-07-06T13:51:48","modified_gmt":"2011-07-06T13:51:48","slug":"how-to-export-a-file-to-iphone-documents-folder-programmatically","status":"publish","type":"post","link":"https:\/\/blog.alwawee.ru\/?p=429","title":{"rendered":"How to export a file to iPhone documents folder programmatically"},"content":{"rendered":"<p>Here I give an example of how to export a file to iPhone documents folder programmatically. I spent a lot of time on managing of how to do it. My main problem was that I couldn&#8217;t find documents folder of iPhone simulator. I couldn&#8217;t write anything to file and I used a wrong way with NSData class. Finally, I found a recipe in Internet and modified it a little bit.<\/p>\n<p>So look at the example:<\/p>\n<p>This is just a method. Firstly, we discover a <strong>documents Directory<\/strong> of a device. Then we <strong>NSLog<\/strong> it in order to find that directory on Mac, if we use iPhone\/iPad simulator. Then we make a file name to write the data to using the documents directory. Then create content &#8211; four lines of text, including even some <strong>non ASCII<\/strong> text(that&#8217; the modification). Then we just save content to the documents directory. Now that file is available <strong>through iTunes in programs tab<\/strong>, in the bottom of it for the given Applicaton. Note that you should add <strong>&#8220;Application supports iTunes file sharing&#8221;<\/strong> line and check it in your Info.plist file for your application in order to be able to use iTunes\/iPhone\/Programs\/Your app to share files. Also note that <strong>encoding:NSUTF8StringEncoding<\/strong> is needed if you want to use non ASCII letters.<\/p>\n<pre class=\"alwawee-code\"><code>&lt;\/p&gt;\n&lt;pre&gt;\/\/Method writes a string to a text file\r\n-(void) writeToTextFile{\r\n\/\/get the documents directory:\r\nNSArray *paths = NSSearchPathForDirectoriesInDomains\r\n(NSDocumentDirectory, NSUserDomainMask, YES);\r\nNSString *documentsDirectory = [paths objectAtIndex:0];\r\nNSLog(@&quot;%@&quot;,documentsDirectory); &lt;\/code&gt;\r\n\r\n\/\/make a file name to write the data to using the documents directory:\r\nNSString *fileName = [NSString stringWithFormat:@&quot;%@\/textfile.txt&quot;,\r\ndocumentsDirectory];\r\n\/\/create content - four lines of text\r\n\/\/NSString *content = @&quot;One;\u041e\u0434\u0438\u043d\\nTwo;\u0414\u0432\u0430\\nThree;\u0422\u0440\u0438\\nFour;\u0427\u0435\u0442\u044b\u0440\u0435\\nFive;\u041f\u044f\u0442\u044c&quot;;\r\nNSString *content = @&quot;One,\u041e\u0434\u0438\u043d\\nTwo\\nThree\\nFour\\nFive&quot;;\r\n\/\/save content to the documents directory\r\n[content writeToFile:fileName\r\natomically:NO\r\nencoding:NSUTF8StringEncoding\r\nerror:nil];\r\n}&lt;\/pre&gt;\n&lt;p&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here I give an example of how to export a file to iPhone documents folder programmatically. I spent a lot of time on managing of how to do it. My main problem was that I couldn&#8217;t find documents folder of iPhone simulator. I couldn&#8217;t write anything to file and I used a wrong way with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[10,9,187,8],"class_list":["post-429","post","type-post","status-publish","format-standard","hentry","category-ios","tag-export","tag-file-management","tag-ios","tag-iphone"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to export a file to iPhone documents folder programmatically - Denis Kutlubaev<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.alwawee.ru\/?p=429\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to export a file to iPhone documents folder programmatically - Denis Kutlubaev\" \/>\n<meta property=\"og:description\" content=\"Here I give an example of how to export a file to iPhone documents folder programmatically. I spent a lot of time on managing of how to do it. My main problem was that I couldn&#8217;t find documents folder of iPhone simulator. I couldn&#8217;t write anything to file and I used a wrong way with [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.alwawee.ru\/?p=429\" \/>\n<meta property=\"og:site_name\" content=\"Denis Kutlubaev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/alwaweemobile\" \/>\n<meta property=\"article:published_time\" content=\"2011-07-06T12:49:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2011-07-06T13:51:48+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/blog.alwawee.com\/?attachment_id=1982\" \/>\n<meta name=\"author\" content=\"Denis Kutlubaev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Kutlubaev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=429#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=429\"},\"author\":{\"name\":\"Denis Kutlubaev\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"headline\":\"How to export a file to iPhone documents folder programmatically\",\"datePublished\":\"2011-07-06T12:49:21+00:00\",\"dateModified\":\"2011-07-06T13:51:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=429\"},\"wordCount\":238,\"commentCount\":0,\"keywords\":[\"Export\",\"File management\",\"iOS\",\"iPhone\"],\"articleSection\":[\"iOS\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=429#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=429\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=429\",\"name\":\"How to export a file to iPhone documents folder programmatically - Denis Kutlubaev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\"},\"datePublished\":\"2011-07-06T12:49:21+00:00\",\"dateModified\":\"2011-07-06T13:51:48+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=429#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=429\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=429#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.alwawee.ru\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to export a file to iPhone documents folder programmatically\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/\",\"name\":\"Denis Kutlubaev\",\"description\":\"iOS Development\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.alwawee.ru\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\",\"name\":\"Denis Kutlubaev\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"caption\":\"Denis Kutlubaev\"},\"description\":\"iOS Developer, creator of Tornado Browser and many other popular apps\",\"sameAs\":[\"http:\\\/\\\/dennis.alwawee.com\"],\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to export a file to iPhone documents folder programmatically - Denis Kutlubaev","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.alwawee.ru\/?p=429","og_locale":"en_US","og_type":"article","og_title":"How to export a file to iPhone documents folder programmatically - Denis Kutlubaev","og_description":"Here I give an example of how to export a file to iPhone documents folder programmatically. I spent a lot of time on managing of how to do it. My main problem was that I couldn&#8217;t find documents folder of iPhone simulator. I couldn&#8217;t write anything to file and I used a wrong way with [&hellip;]","og_url":"https:\/\/blog.alwawee.ru\/?p=429","og_site_name":"Denis Kutlubaev","article_publisher":"https:\/\/www.facebook.com\/alwaweemobile","article_published_time":"2011-07-06T12:49:21+00:00","article_modified_time":"2011-07-06T13:51:48+00:00","og_image":[{"url":"http:\/\/blog.alwawee.com\/?attachment_id=1982","type":"","width":"","height":""}],"author":"Denis Kutlubaev","twitter_misc":{"Written by":"Denis Kutlubaev","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.alwawee.ru\/?p=429#article","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/?p=429"},"author":{"name":"Denis Kutlubaev","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"headline":"How to export a file to iPhone documents folder programmatically","datePublished":"2011-07-06T12:49:21+00:00","dateModified":"2011-07-06T13:51:48+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.alwawee.ru\/?p=429"},"wordCount":238,"commentCount":0,"keywords":["Export","File management","iOS","iPhone"],"articleSection":["iOS"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.alwawee.ru\/?p=429#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.alwawee.ru\/?p=429","url":"https:\/\/blog.alwawee.ru\/?p=429","name":"How to export a file to iPhone documents folder programmatically - Denis Kutlubaev","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/#website"},"datePublished":"2011-07-06T12:49:21+00:00","dateModified":"2011-07-06T13:51:48+00:00","author":{"@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"breadcrumb":{"@id":"https:\/\/blog.alwawee.ru\/?p=429#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.alwawee.ru\/?p=429"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.alwawee.ru\/?p=429#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.alwawee.ru\/"},{"@type":"ListItem","position":2,"name":"How to export a file to iPhone documents folder programmatically"}]},{"@type":"WebSite","@id":"https:\/\/blog.alwawee.ru\/#website","url":"https:\/\/blog.alwawee.ru\/","name":"Denis Kutlubaev","description":"iOS Development","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.alwawee.ru\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7","name":"Denis Kutlubaev","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","caption":"Denis Kutlubaev"},"description":"iOS Developer, creator of Tornado Browser and many other popular apps","sameAs":["http:\/\/dennis.alwawee.com"],"url":"https:\/\/blog.alwawee.ru\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=429"}],"version-history":[{"count":0,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/429\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}