Is it possible to open a download ebook file via iBook? - iphone

I got a question, which is, what if I can download a ebook file, eg .epub or PDF, then I list this file on a tableview, now I select one of the books.
Can I open via iBook?
Or I need to implement a reader to open the file?
Also got another question , I download a pdf file in my folder
The path I log it out , looks right
Here is the code:
NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
NSString *ePubSubFolder = [docPath stringByAppendingPathComponent:#"Books"];
NSString *pdfPath = [ePubSubFolder stringByAppendingPathComponent:[NSString stringWithFormat:#"%#",self.pdfFileName]];
CFURLRef pdfURL = CFURLCreateWithFileSystemPath (NULL,(CFStringRef)pdfPath, kCFURLPOSIXPathStyle, FALSE);
NSLog(#"PDF URL: %#", pdfURL);
pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
CFRelease(pdfURL);
The log result is
../iPhone%20Simulator/4.3.2/Applications/06BA5929-3531-4AC3-B524-6CC74DC7E2C9/Documents/Books/Repeat%20After%20Me%20User's%20Guide.pdf
Do I did something wrong ?I won't show any thing on my view.
Many thanks for all reply or answer :-)

in IOS when you open a pdf using any application you get an option on the top right corner click on it and you can see options like open in ibooks etc.. I have tried this with many apps.
this is what I do to use some pdf on my ios devices.. load the file into a dropbox folder on the comp open it in the device in dropbox and then move it over to ibooks..

Related

Objective C - how to access a file from iPhone/Application/Documents

I am using the following method to write image files out to the Applications/Documents folder:
- (void)saveImage:(UIImage *)image toFile:(NSString *)fileName
{
//get the data from the representation
NSData * binaryImageData = UIImagePNGRepresentation(image);
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
//write the data to a file
[binaryImageData writeToFile:[basePath stringByAppendingPathComponent:fileName] atomically:YES];
}
I thought I could just copy them to my computer, but that's not working out for me. Then, I decided to try to write the files to my hard drive. Nope. I guess that was a dumb idea, too.
I am processing bitmap images that I just want to capture somewhere (not on the device) where I can then retrieve them for testing. I've mucked with this for several hours and now it's getting late and I'm tired. Definitely ready for a little help.
Thank you in advance.
This question was answered by Rajesh Choudhary, but there were a few more hoops to go through to get the images off the phone and I wanted to post the entire process to help someone else in the future. So, here are the steps.
Enable file sharing from your app's info.plist file:
Use the code in the original post to write the file out to the
application /Documents folder.
Run your app to save the file to the iPhone application /Documents folder.
Check that your files were save by opening Organizer and selecting the iPhone running the application and selecting the application. The saved files will be located in the Documents folder in Data files in Sandbox.
To access them, open iTunes. Select the device running the application and select the Apps tab. Then, scroll to the File Sharing section, select the app and voila! The documents folder will display all your saved files on the device.
You can then select one or more of the files and click the Save to... button to save the files to your computer.
if you want to use images from device to your computer... you have to enable file sharing option in your app... When you enable it from your app's info.plist file you can see document folder in itunes.
Select you app from list and then, You can put & get files to/from document directory.
if you want to access image from document directory in app so you can use this method.
-(UIImage *)getImageFromDocumentDirectoryForFileName:(NSString *)fileName
{
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
UIImage *image =[UIImage imageWithContentsOfFile:[basePath stringByAppendingPathComponent:fileName]];
return image;
}

how to find a file that was created programmatically directly from my iphone

I've created an image file in an application and stored it in the fileDirectory using the following code:
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString * basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
UIImage* videoImage = [self resizeImage:[UIImage imageWithData:self.videoImageData] toWidth:width andHeight:height];
NSData *imageData2 = UIImageJPEGRepresentation(videoImage, imageQuality);
[imageData2 writeToFile:[basePath stringByAppendingPathComponent:#"myfile.png"] atomically:YES];
now from my iPhone device how can i find and open this file?
In Xcode you can go to Window->Organizer and select the Devices tab.
Under the device in the panel on the left you will see Applications. Select your application to see the file system for the app sandbox. Select Download to save all the data to the mac (as a package file).
You can right-click a package file to browse as a folder by selecting Show Package Contents from the context menu.
You would need to connect your iPhone to a Mac to see it. iExplorer does the trick.
imageData2 writeToFile:[basePath stringByAppendingPathComponent:#"/myfile.png"] atomically:YES];
you missed back slash

HTML file creation with image

I created an HTML file programmatically with images sources. The images are stored in the documents directory. The problem is that when I give the image source path as document directory path the images are not shown in Windows.
So, I choose the second option is to give only the image's name instead of whole path. Then it work well on Mac & Windows, but now images are not shown on the device's UIWebView.
Then I selected to open the HTML file in Safari insted of UIWebView, but the safari could not be opened because URL becomes NULL.
My code to open Safari is as follow:
NSLog(#"%#",documentsDirectory);
NSString *urlStr = [NSString stringWithFormat:#"%#/AccReport1.html",documentsDirectory];
NSLog(#"urlStr :: %#",urlStr);
NSURL *url1=[[NSURL alloc]init ];
url1 = [NSURL fileURLWithPath:urlStr];
NSLog(#"url :: %#",url1);
[[UIApplication sharedApplication]openURL:url1];
I want to mail the HTML file that contains images. And these HTML file and images are stored in document directory. I want to show this HTML file with images in windows browser, mac browser and iphone's safari.
How to do this?
One of the simple way to solve your problem is to keep Images and HTML file in same directory and refer those images in HTML files just by name and if you put them in a folder then give the complete path.
The images are not showing because the image path specified within the HTML code is not the documents directory path.
I suggest you might have to construct an html string and then subject the uiwebview to load that string
NSString *htmlString = [NSString stringWithFormat:#"<html><body><img src=\" %#/image.png \"></img></body></html>",documentsDirectoryPath];
[webView loadHTMLString:htmlString baseURL:nil];

How to open other application from our application in iphone

I create one application in my iphone so i want to do if i open my application the i am give one button if .I click that button then.I want to open other 10 application which is already in my iphone that application i have to open in my application which i create
can we use this as par my required
NSString *documentdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *tileDirectory = [documentdir stringByAppendingPathComponent:#"xxxx/Tiles"];
NSLog(#"Tile Directory: %#", tileDirectory
Try this link. It will show you almost all the apps that you can open from your app using the URL Schemes and as the #trojanfoe has said, it is a duplicate.

(IPHONE) Big confusion to read/write the same file from resource folder

i've read several thread for this question but unfortunatly not found the answer to my problem :(
i have a xml file in resource folder, and i need just to re-write the same file;
the app logic is:
display data loaded from file
add new data to the same file
for read a file my code is:
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"myfile" ofType:#"xml"];
NSData *dataXml=[NSData dataWithContentsOfFile:filePath];
for re-write the same file:
NSString *myDataString = #"?xml version=""1.0"" encoding=""UTF-8""?";
NSString *path = [[NSBundle mainBundle] pathForResource:#"myfile" ofType:#"xml"];
BOOL ok=[myDataString writeToFile:path atomically:YES encoding:NSUnicodeStringEncoding error:nil];
For read works fine, but when i try to write, the file is not updated, but it was created another one in another folder, i've tested this in the simulator noting that an app is in a folder like this:
Users/user/Library/Application Support/iPhoneSimulator/Users/Applications/05279766-7B2C-4FC0-BFB0-D87A158A3337/
where there are 3 folder (Documents,tmp,Libary) and the bundle file .app (where there is my xml file)
My question are: is my logic wrong? in wich way are managed app folders in the device??
thanks in advance and sorry for the long thread!
You cannot write files into your application bundle; it's read only (on the device, at least; you may be able to do this in the Simulator).
What you should do is use your ~/Documents folder for the file. If it's not there, first read it from your bundle, then write it out to ~/Documents, and from then on, read it from there.