ipad:How to open keynote file on uiwebview - objective-c

- (void)viewDidLoad
{
[super viewDidLoad];
[self loadDocument:#"mykeynote.key.zip" inView:webView];
}
-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView1
{
NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil];
NSURL *url = [NSURL fileURLWithPath:path];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView1 loadRequest:request];
}
I received a error message after run this code "Sorry, this document can't be viewed."I am currently working keynote 09.How do i open the keynote file in uiwebview? Help me!

There's some information about it here:
http://developer.apple.com/library/ios/#qa/qa1630/_index.html
Specifically what you're looking for is this:
iWork '09 documents do not use a package format and must not be ZIP compressed.
So you shouldn't be compressing your keynote file. This was only required for '08 and earlier.
Since older iWork documents are packages, they are directories. You can use NSFileManager's attributesOfItemAtPath:error: function along with the key NSFileType to see if it's a directory (value should be NSFileTypeDirectory).
If the file is a directory you can use a library like ZipArchive to compress it.

Related

Objective-C UIDocumentInteractionController Couldn't issue file extension for path

I am having an issue with UIDocumentInteractionController, here is my code:
NSURL *URL = [NSURL fileURLWithPath:#"http://www.domain.com/pdf/35.pdf"];
//NSURL *URL = [[NSBundle mainBundle] URLForResource:#"35" withExtension:#"pdf"];
if (URL) {
// Initialize Document Interaction Controller
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
// Configure Document Interaction Controller
[self.documentInteractionController setDelegate:self];
// Preview PDF
[self.documentInteractionController presentPreviewAnimated:YES];
}
my console log says this:
Couldn't issue file extension for path: /http:/www.domain.com/pdf/35.pdf
and in my app it displays a gray background and says 35.pdf Portable Document Format (PDF)
what am i doing wrong?
An http URL is not a file URL.
This:
NSURL *URL = [NSURL fileURLWithPath:#"http://www.domain.com/pdf/35.pdf"];
needs to be:
NSURL *URL = [NSURL URLWithString:#"http://www.domain.com/pdf/35.pdf"];
But note that UIDocumentInteractionController expects a URL to a local resource, not an Internet URL. So you can't use the above URL at all.
You would need to download and save the PDF file locally first and then create a proper file URL to the local file.

How do I find the URL of a mp4 resource file?

Why can't I find a resource when it's an ".mp4"?
My code is:
- (IBAction)babelFishButton:(id)sender {
NSURL *url = [[NSBundle mainBundle] URLForResource:#"BabelFish" withExtension:#"mp4"];
MPMoviePlayerController *player =[[MPMoviePlayerController alloc] initWithContentURL: url];
[player prepareToPlay];
[player.view setFrame: self.imageView.bounds]; // player's frame must match parent's
[self.imageView addSubview: player.view];
[player play];
}
BabelFish.mp4 exists in the project navigator, and finder tells me it's in the app root folder, along with main.m, etc.
But the video does not play because url is nil (the file is not being found). I can paste in a copy of the file and rename it "BabelFish.txt", change the extension in the code and it finds the file.
Why won't it find "mp4" files? How do I get the URL of an mp4 file?
Jeff
Try this:
NSString *myUrlSTR = [[NSBundle mainBundle] pathForResource:#"BabelFish" ofType:#"mp4"];
Another thing make sure that your file is not only listed in your Project Explorer, but also included in your Copy Bundle Resources list.

ios - Showing a Download progress UIViewController

After implementing the HCDownload for iOS into my app I am successfully able to display the downloading progress of a file.
The problem is that the guy who wrote it, didn't use Xcode to write the module, so even though it should, it does not really work nice when trying to integrate with a project.
These are the main issues I have with it:
If you do a [self.navigationController pushViewController:dlvc animated:YES]; or a [self presentViewController: animated: completion:]; then it shows when it is initiated. I can get out of it, by navigating back, but then when I return to it, it is blank - so I cannot see what the progress is of the download. The download however keeps going, because it appears in my documents folder. ( I use ASIHTTP framework)
Now I am working with storyboard in this project, and because this does not come with a XIB file I thought (which has kinda worked in the past) I could just have a UITableViewController and have this as its Custom Class, but it does not play ball.
Is there a XIB based Download manager FrameWork that someone can point me too, or has anyone had luck with this one?
PS I know Storyboards do not use XIB files, but that way it is easier to integrate into storyboard than no UI files at all:-)
Kind thanks for the tips.
Edit
Here is the code where I implement it:
HCDownloadViewController *dlvc = [[HCDownloadViewController alloc] init];
dlvc.delegate = self;
NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
dlvc.downloadDirectory = documentDirectory;
NSString *fileSave = [_streamingURL lastPathComponent];
NSURL *url = [NSURL URLWithString:_streamingURL];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[dlvc downloadURL:url userInfo:nil];
// Add your filename to the directory to create your saved pdf location
NSString *pdfLocation = [documentDirectory stringByAppendingPathComponent:fileSave];
NSString *cachesDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
// Add your filename to the directory to create your temp pdf location
NSString *tempPdfLocation = [cachesDirectory stringByAppendingPathComponent:fileSave];
if (!networkQueue) {
networkQueue = [[ASINetworkQueue alloc] init];
}
failed = NO;
[request setTemporaryFileDownloadPath:tempPdfLocation];
[request setDownloadDestinationPath:pdfLocation];
[request setDownloadProgressDelegate:progressBar];
[request setShowAccurateProgress:YES];

How can I play an mp4 resource with AVPlayer?

I have included an mp4 resource in my project navigator. I want to play it in an AVPlayer. I know how to create an AVPlayerItem for the AVPlayer object, and so now I'd like to load the appropriate AVAsset into it pointing to my mp4 resource. The problem is that AVAsset only has an assetWithURL: method to create an AVAsset. I want an assetWithName: method, but that method does not exist. How can I play my mp4 file if I don't have a URL for it? If it's not possible to play via name reference, how can I get a file URL for my mp4 file?
To get the URL, use
[[NSBundle mainBundle] URLForResource:#"my_video" withExtension:#"mp4"]
It will probably be in your main bundle, you can get its URL with
- (NSString*) saveFilePath: (NSString *) add
{
NSString *filename = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:
[[NSBundle mainBundle] pathForResource:add ofType:#"mp4"]isDirectory:NO]]];
return filename;
}
Copy this into your code and then do [self saveFilePath:#"Name of your file"] to get the URL.
Full code:
AVPlayer *player = [[AVPlayer alloc] initWithURL:[self saveFilePath:#"fileName"];
[player play];

Adding text file to Xcode project and using it in app

I have a .txt file (in plain text format) and I would like to integrate this into a iOS app I am starting to write. The info in the text file must be searchable by the app. Is there a way to do this? If so, what would be best way to do so? Or would I need to add this text file into ViewController.m in code instead?
You will need to add the txt file to your project and then read it into memory. Here is one way to read the entire contents into memory at once:
NSString *path = [[NSBundle mainBundle] pathForResource:#"yourTextFile"
ofType:#"txt"];
NSError *error = nil;
NSString *data = [NSString stringWithContentsOfFile:path
encoding:NSUTF8StringEncoding
error:&error];
if (error) {
// handle the error condition
} else {
// continue your processing
}