Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6712937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:19:11+00:00 2026-05-26T08:19:11+00:00

My app writes an encrypted data of the user info/preferences into a file, and

  • 0

My app writes an encrypted data of the user info/preferences into a file, and reads from that file the next time the app is opened.

Writing a file:

- (BOOL)writeFile:(NSString *)data:(NSString *)fileName {
  return [data writeToFile:fileName
                atomically:YES
                  encoding:NSUTF8StringEncoding error:nil];
}

Reading a file:

- (NSString *)readFile:(NSString *)fileName {
  NSData *data = [NSData dataWithContentsOfFile:fileName];
  NSString *str = [[[NSString alloc] initWithData:data
                                         encoding:NSUTF8StringEncoding] autorelease];
  return str;
}

This works fine on the emulator. The files are written and read as expected. Is there anything I have to setup for file read/write on devices?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:19:12+00:00Added an answer on May 26, 2026 at 8:19 am

    The filename has to be in the documents directory. The simulator won’t have as many restrictions on where it can write files as the device does.

    Obtain the documents directory as follows:

    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    NSString *fileName = [documentsDirectory stringByAppendingPathComponent:@"myfilename.extension"];
    

    Pass this into your functions above and you should be fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an app that writes data out to a .plist from a
I have a Rails app that has 2 clients -- an iOS app reads/writes
im making an app that writes to a .txt file and at the end
I'm building a Mango app that writes data to a SqlCe database; I have
I know that I can load an app.config file from a different location using
I have a Delphi 2006 app that writes to a file and then regularly
I have a Delphi app that regularly writes to a local disk file. Occasionally
I am writing a VB.Net app that reads and decrypts the response from a
am working on a java(tomcat) app. that sometimes writes to stdout. But I notice
My app writes a lot of XML data, and randomly the last line of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.