Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
iOS Forensics Cookbook

You're reading from   iOS Forensics Cookbook Over 20 recipes that will enable you to handle and extract data from iOS devices for forensics

Arrow left icon
Product type Paperback
Published in Jan 2016
Publisher
ISBN-13 9781783988464
Length 184 pages
Edition 1st Edition
Tools
Concepts
Arrow right icon
Authors (2):
Arrow left icon
Bhanu Birani Bhanu Birani
Author Profile Icon Bhanu Birani
Bhanu Birani
Mayank Birani Mayank Birani
Author Profile Icon Mayank Birani
Mayank Birani
Arrow right icon
View More author details
Toc

Saving data using the RAW file

In the previous section, you learned about the Document directories. Now, in this section we will explore this in more detail. You will learn about saving RAW files in our application's document directory.

Getting ready

We will use the preceding project for this section as well. So, open the project and follow the next section.

How to do it...

Perform the following steps to write data into your Documents directory:

  1. Now, we will create a .txt file in our folder (which we created in the document directory). Customize the code in viewDidLoad: as follows:
    dataPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"myfile.txt"];
    NSLog(@"%@", dataPath);

    The preceding code will create a .txt file of name myfile.txt.

  2. To write something into the file, add the following code:
    NSError *error;
    NSString *stringToWrite = @"1\n2\n3\n4";
    dataPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"myfile.txt"];
    [stringToWrite writeToFile:dataPath atomically:YES encoding:NSUTF8StringEncoding error:&error];

    The writeToFile method is used to write data in our file.

  3. Now, to read the data from the file, there's the stringWithContentsOfFile method. So add the following method inside the code:
    NSString *str = [NSString stringWithContentsOfFile:dataPath encoding:NSUTF8StringEncoding error:&error];
    NSLog(@"%@", str);
  4. To see the mayflies.txt file in the Documents directory, go to the GoToFolder finder and paste dataPath from the console. It will take you to mayflies.txt. The final file should look something like the following screenshot:
    How to do it...
  5. In the screenshot, you can see the two files have been created. As per our code, we have created myfile.txt and myfile.pdf. We have also created MyFolder in the same Documents folder of the app.
You have been reading a chapter from
iOS Forensics Cookbook
Published in: Jan 2016
Publisher:
ISBN-13: 9781783988464
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image