I have a problem for saving pdf file on iPhone.
I have used the following objective c code to save pdf file:
NSURL *pathURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSString *filePath = [pathURL.path
stringByAppendingPathComponent:#"filname.pdf"];
[[NSFileManager defaultManager] createFileAtPath:filePath
contents:pdfdata
attributes:nil];
I can check whether the file is saved or not correctly using webview.
I can check the contents of the saved pdf file using webview.
But I can't find the saved file on both simulator and device.
Where can I find my saved file on iPhone?
If anyone knows the solution for my issue then please advise me.
Thanks.
Your .pdf file was saved in your application document folder. So, You can easily check on simulator. Like below
Print a downloaded file path
print(filePath)
then go to
Finder -> Go Menu -> Go to folder
and paste the filePath
This is the path of your application document folder
Related
I am using FMDatabase in my project I need to check the data in the table. Is there any tool or anything else that will help me see the db entries which is on real device ?
If you want to check data from of your applications sqlite file check it on simulator version is easy. Where you initialise database, print documentDirectory path in your application:
// Get Document Directory path of the device.
- (NSString*) documentsDirectory{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
return [paths objectAtIndex:0];
}
Navigate to that path in Explorer by cmd+G and pasting the path in text box. You'll see one .sqlite file in that folder. Open it with any sqlite explorer, I use Mozilla AdOn or SQliteManager.
But if you wanna check db from your device:
Open device manager Xcode
Select your device
Click on installed app installed app in right pan
Select your app
Download it (see attached image)
And then explore the package to find sqlite file in it.
I am developing an iOS project. There, I am having to upload images to to PHP server. So I choose some images from gallery in simulator for check up. Selected image is stored inside simulator. But I couldn't find that folder. So image is going empty to server. How to find that folders?
That image stored path is below
User/Guest/Library/developer/core simulator/devices/1ABD8156-4A55-4189--BDCD-DA6F7CSB2229/data/containers/data/applications/1559E24-9738-447D-8888-EEC9E29D4D39/Documents/Photo.jpg
But here I can found until
User/Guest/Library/developer/core simulator/devices/1ABD8156-4A55-4189--BDCD-DA6F7CSB2229/data/containers/data/applications/
How can I solve this. Please help me.
Note: i am using xamarin studio for development.
This would get u the simulator directory.
[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
As iam a newbie in iPhone app development, please help me with this issue.
According to my code, iam trying to create a folder called "New Folder" in the Documents. When i run this code, iam able to get the output in NSLog with the complete path and i can see where the folder is getting created in my system as well. But the problem is iam not able to see this folder in iPhone simulator. Is there any way to see this folder which i have created in simulator?
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(#"%d",[paths count]);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/New Folder", documentsDirectory];
NSLog(#"Path is: %#",filePath);
NSFileManager *manager = [NSFileManager defaultManager];
NSLog(#"%d",[manager createDirectoryAtPath:filePath withIntermediateDirectories:YES attributes:nil error:nil]);
NSLog(#"Folder created");
Yes you can see this folder by going through the following steps....
Open Your Finder Window. Go to Library -> Application Support -> iPhone Simulator -> Choose the type of Simulator(like 6.1, 5.0 etc) - > Applications -> Check the project of the simulator by its Name after going into the numbers -> Document.
This is your Document Directory. You will find your files here.
For more simplicity for viewing folders in document directory follow the steps:
1) NSLog the path and then copy it from console.
2) Open finder press Command+shift+g
3) Paste the path and press go.
You can see folder created manually by using following steps :
Go to Finder Window
Select Application Support
iPhone Simulator
Now, Select simulator version (say 6.1)
Applications (contains list of application that are executed)
Select your Application folder
Documents contains user created folders.
This is shown in screenshot
I am writing an IPhone application in witch I downloaded files and photos locally in the Supporting Files folder ( in the right panel of xcode ), these files are downloaded also in a web server, what I want is that if the application detect that these files are updated in the web server , it replace them with the new content in the Supporting Files I used
NSArray* pathArray = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory,NSUserDomainMask, YES);
documentsDirectory = [pathArray objectAtIndex:0];
NSString* localFile = [documentsDirectory stringByAppendingPathComponent:#"test.txt"];
[data writeToFile:localFile options:NSDataWritingAtomic error:&error];
the code works well but the problem is that it replaces content of files in
Library/Application Support folder and not the Supporting Files so when I do :
NSBundle *thisBundle = [NSBundle mainBundle];
NSString *TextURL = [thisBundle pathForResource:#"test" ofType:#"txt"];
NSURL *instructionsURL = [NSURL fileURLWithPath:TextURL];
NSString *TextString = [NSString stringWithContentsOfURL:instructionsURL];
mayText.text = TextString;
the old content is displayed and not the updated one
How can I change my code to replace files in Supporting files directory every time Application Support files are changed ? And what is the difference between these two folders? Thank you.
You can't. iOS Apps on the device are signed, changing the bundle's content would break that signing. And as all files that are managed by Xcode and added to a target go to the bundle, they must not be changed.
Instead download the files to a sandbox directory, such as Documents and access it there.
Also note that Supporting Files iin Xcode is not a directory but a group. It juste groups it content inside the Xcode project but does not organize the files in a directory on file system level.
I have created a database (IOS 5.1) with XCode 4.3.3 for the iPad and have set it up so that the user can backup and restore the database file (*.sqlite) to DropBox. Everything works fine...
Now I would like to do the same process but, set it up for iCloud. Looking for the following function:
Tap a button to backup the *.sqlite file from the Apps Document Directory up to iCloud at users preference.
Tap a button to copy the *.sqlite file down from iCloud to the Apps Document Directory.
I have been struggling trying to find the solution, any help will be greatly appreciated.
For moving any file to and from icloud you can use this code below.
[[[NSFileManager alloc]init] setUbiquitous:YES itemAtURL:your iCloudURL destinationURL:localDirectoryURL error:&errorsss];
only thing is if you are moving to icloud the code should be :
[[[NSFileManager alloc]init] setUbiquitous:YES itemAtURL:localDirectoryURL destinationURL:your_iCloudURL error:&errorsss];
and if you are getting it from iCloud to Apps Documents directory
[[[NSFileManager alloc]init] setUbiquitous:NO itemAtURL:your_iCloudURL destinationURL:localDirectoryURL error:&errorsss];