How would you Open PDFs Stored on Your iPhone - iphone

I am creating an application that downloads one of its screens as PDF and stores it in a location such as /var/mobile/Applications/B19F4B52-F19B-46F8-9CE0-FA4D4656367B/Documents/SecondScreen1.pdf.. I have no idea what this location is and i want to open this pdf later as well.. Meaning I want the user to be able to easily access his PDFs etc. Which means storing it in a location that is accessible to him. I'd like to know how i can direct a path or manage to store it in some other applications storage (such as photos or so).. Currently this is where i am storing the file i need to store.. -
NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
NSString* documentDirectory = [documentDirectories objectAtIndex:0];
NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
// instructs the mutable data object to write its context to a file on disk
[pdfData writeToFile:documentDirectoryFilename atomically:YES];

You can only store it in your apps sandboxed file hierarchy. The documents folder is usually the recommended one for files that should be exchangeable (to access via iTunes eg). But you can create your own directory too. you can't access other apps file structure. You could use iCloud or Dropbox I suppose.
But to make it accessible to the user, I would store it in documents as you did and enable iTunes file exchange. Also you could easily create a mail composer to send your PDF as email.

Related

What is suitable location for creating sqlite file?

Actually, My app got rejected from app store because i am storing about 9 MB data in document directory.
What is better and suitable location store image cache and to create sqlite database file?
The image cache has to go into the cache directory. A cache should not be included in a backup because you can recreate those images easily.
If the sqlite file stores user data you should put it into the document directory. It has to be included in device backups because you can't recreate it and the user would lose all his data when he restores his device from a backup.
If the sqlite file is downloaded from the web and it is never changed by the user put it into the cache directory too. On iOS 5.0.1 and later you could put that file into the documents directory and set the "Do not backup"-Attribute. However, on device with iOS 5.0 or earlier you HAVE to put that file in the caches directory.
NSString *cacheDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
The concern area is the iOS 5.0, which supports iCloud, but does not recognizes “do not backup” attribute. In this case, all the data of the app inside documents directory is likely to get backed up to iCloud. For the iOS versions below 5.x:
the iCloud backup is not valid.
the "do not back up" flag is not relevent. It would not produce any warnings during compilation.
Hence the data can be kept in the documents directory, with "do not back up" flag appropiately added to the contents (files/folders), for all the versions. The problem is for the version 5.0 only.
if you have lot of image in Your application.then sotre images in any image store site and use link of image. its better for You.

iOS : Apps must follow the iOS Data Storage?

My iOS app was rejected because I use the /Document directory to store downloaded images.
I will move the downloaded images in the /Library/Caches directory to solve my problem.
But my sqLite database also contains elements manually created by the user.
This file must be copied into the /Library/Caches directory or /Documents directory to be accepted by the Reviewer ?
Sincerely,
Maxime
As per the iOS Storage Guidelines (which can be found at http://developer.apple.com/icloud/documentation/data-storage/) you should put all user-generated content in the Documents directory and all re-downloadable content in the Caches directory. So you should be fine putting the sqLite database there.
The background on this is that starting with iOS 5 the Documents directory is backed up to iCloud. As a lot of apps tend to store their complete data there the iCloud backups get rather large, which uses up the free space and creates network traffic, both of which in turn anger the user because he/she wonders why. To mitigate this Apple now seems to take a much closer look on what is saved into the Documents directory and if this is possibly regeneratable content (e.g. downloadable files).
Beware, that the Caches directory can and will be purged on iOS 5 by the operating system at times when the free space on the device gets low. Thus your app cannot longer just assume that everything is there as it was before but you rather have to re-check every time you access something out of your cache.
The data manually created can be stored with in your app directory.
You can use below code to get the current directory -
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
and then append you file name to get the full path.
NSString *fileName = [documentsDirectory stringByAppendingPathComponent:#"myfile.format"] ;

Storing to plist works on simulator but not on device

I currently add data to a NSMutableArray and then read back from it to populate a UITableview. This works fine on the simulator, but when testing on the device it doesnt work. The app still reads from the plist, so if I manually add data to it the app displays it in the tableview. But Cannot read or write to it on app ?
I use the current code
newTitle = [NSString stringWithFormat:#"%d_%#",[Daily_QuoteViewController counter], t];
[plistArray addObject:newTitle];
[plistArray writeToFile:filepath atomically: YES];
I have read that the list needs to be serialized as well, but others say this isnt necessary?
Any help is appreciated.
Thanks
Are you sure your app has write permissions to the location you are trying to write the plist to? There are differences between the file system access on the simulator and the actual device.
Update: You can read more about the folders available for your app in iPhone Application Programming Guide: A Few Important Application Directories. The standard way of getting the locations of these folders is described in iPhone Application Programming Guide: Getting Paths to Application Directories. Here's an example how to get the Documents folder and construct a path to a file in it:
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory,
NSUserDomainMask, YES
);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSURL *urla = [NSURL fileURLWithPath:[documentsDirectory
stringByAppendingString:#"/myinfo.plist"]];
Which application folder you will use depends on the actual content of your file and the intended use.

How can I store an image in the iPhone device file system so that later if I want I can retrieve it and use in my app?

I am trying to store an image in the device through my program. I am able to store the image in the sandbox. After quitting the app when I run it again the address of the sandbox changes so I am not able to retrieve it and use it in the next run.
Please help.
Have a look at this stackoverflow question.
To get a path to the apps own document path you do
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
For a complete description of how to use the filesystem on the iPhone see the documentation here
Files in iPhone OS share space with the user’s media and personal files on the flash-based memory. For security purposes, your application is placed in its own directory and is limited to reading and writing files in that directory only. The following sections describe the structure of an application’s local file system and several techniques for reading and writing files.

Does iPhone API allow application read/write to iPhone's filesystem?

My iPhone app (well, idea of it) needs to do changes to iPhone's filesystem. Does iPhone API allow that?
Your app has its own piece of filesystem that you can read from and write to but you can't access anything outside that, ie you cannot access the filesystem areas of other apps or the OS itself.
Yes Cocoa Touch for iPhone OS allows file access. With the caveat that it naturally only allows file access for files that the current user has read-write permissions to access. Each application runs as single user, and really only have access to it's own small sandbox of files. So you will not be able to access system files, or files from another application.
There are two main directories that you might want your app to access:
NSDocumentDirectory - Analogous to you own Documents folder, the contents of this folder is backed up when you synch the device.
NSCachesDirectory - This one resides in /Library/Caches/ and is not backed up when synching the device.
You get the path to these directories using the NSSearchPathForDirectoriesInDomains function. When searching you will get an array of potential paths, it is safe to use the first path as long as you only search in the user domain. For example:
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString* docsPath = [paths objectAtIndex:0];
Once you have a path you can work away with your files using the default file manager. For example remove a file:
NSFileManager* fm = [NSFileManager defaultManager];
[fm removeItemAtPath:filePath error:NULL];
i just wrote a tutorial on how to do this using NSMutableArrays that you can check out that should help you. http://idevkit.com/iphonedev/2009/09/saving-nsmutablearrays/
if you have anymore questions on it lemme know and ill add to it