Creating Files In The iPhone

We crate here a files in the application’s Home directory. To make things interesting, we load a web page from the Internet using the http protocol and store that html file in tmp. After that, we use a web view to load the html from the tmp directory and present it to user. We will see, these tasks can be easily achieved using the rich APIs available.

Step 1: Create a Window base application using the template . Give the name FileCreate.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Highlight the classes folder in Groups & Files. Select File -> New File from the menu. Select the UIViewController subclass from the CocoaTouch Classes and click next, give the name of the file FileCreateViewController.m and ensure the Also Create “FileCreateViewController.h”.

Step 4: The declaration of the application delegate class used in the file creation and local file view. So make the following changes in the FileCreateAppDelegate.h file.




Step 5:  The implementation of the application delegate. The delegate simply uses  the FileCreateViewController as a subview of the main window.




Step 6: In the ViewController header file we create UIWebView instance which will be used to visualize the contents of the local file in tmp. We declares two methods for the creation and visualization of the html file in tmp.




Step 7: In the FileCreateViewController.m file, the viewDidLoad method is invoked once the view has been loaded. It creates the file by invoking the createAFileInTMP method and after that it loads the web view with the downladed file by invoking the loadWebViewWithFileInTMP method.




Step 8: Now compile your application and run onto the simulator.

Leave a Comment:

1 comment
Kunal says March 23, 2011

Doesn’t work. Incomplete implementation of class error. Can you a provide working code ?

Add Your Reply