After I created a Objective-c class in my project based on JosephH example. I imported it in my bridging header file.
I was actually able to make it work using a .pdf file in the main bundle
NSString *file = [[NSBundle mainBundle] pathForResource:#"hello-world" ofType:#"pdf"];.
which returns:
"/var/containers/Bundle/Application/63F34E6B-75A7-4CC0-9149-9DF2861DF3A2/sempre-editora.app/hello-world.pdf"
It did render everything all right, zooming and everything. but when I try to render a file in my "Documents" folder it just doesn't work. I even tried to just put this "hello-world.pdf" file inside my "Documents" to try it out and it still doesn't work.
This is the path of my documents file:
"/var/mobile/Containers/Data/Application/AF776E50-FAAC-4274-824F-4F9634E072F6/Documents/70-10"
What could be the problem? I'm sure this is the correct path for my file, and it actually exists, the framework doesn't throw any error but I just get a gray background.
I thought it could be because my file doesn't have an extension but when I add a .pdf to my file and try to render it, it crashes.
After some tests I realised that when the PDF has two pages, and I go to the second page, it actually renders the pdf.
Related
I have a data file that I need to include with my app when I distribute it. When loading any files in the app, I prefix the file name with:
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
This works great for anything I create within the app (and for reading back), like files I download in response to a user action. But I can't for the life of me figure out how to place files there when I build my app in Visual Studio.
I've tried making a "Documents" subdirectory in the special "Resources" folder, but that didn't work (I tried setting the "Build Action" to both BundleResource and Content). When I look at the folder for my app (from using the simulator) I can see that in the "Documents" folder there's all the files I downloaded, but I can't find my data file that I'm trying to bundle ahead of time. I even searched my entire hard drive on the Mac and still couldn't find said data file.
The data file isn't an image, if it matters. Just raw binary data. How do I set it up so that this file goes into the proper documents directory at compile time, so that I can read it using the SpecialFolder.MyDocuments prefix? Thanks.
You can't. You can include files in your app bundle, and then at startup copy them from the bundle into a user folder. But this won't happen automatically.
I have been working on a project in phonegap that requires an iOS tab bar at the bottom. I haven't been able to find a working plugin so with the little knowledge I have in objective C, I took this one and modified it so it works with what we need:
https://github.com/tblomseth/cordova-ios-tab-bar
(note that I didn't change anything with the tab bar function)
I am trying to add custom images to my tab bar, and I understand that I can apply said image with the 3rd parameter defined in the www/tab-bar.js file.
TabBar.prototype.createTabBarItem = function ( name, label, image, options ) {}
My problem is i don't know enough about how phonegap build compiles the application to know how to reference the image for the ios code to take over.
The code that takes the image and applies it to the tab is the following:
item = [[UITabBarItem alloc] initWithTitle:title image:[UIImage imageNamed:imageName] tag:tag];
as defined in src/ios/CDVTabBar.m of that repo, but my question is how do I reference the file name for the image? I've tried the following:
Full path
single file name
single file name with reference in config.xml file
None of the above methods have worked.
I was able to figure this out!
I first thought that the image was moved into some kind of bundle that I needed to know the path to, however its not, it's placed in a file similar to a plist lookup.
My file ended up being called www/img/icons/tabs/history.png when i was using:
/www/img/icons/tabs/history.png
history.png
/img/icons/tabs/history.png
The way I was able to find what to call the file is as follows:
Download the APK file from PhoneBapBuild on my Mac
change the .apk extension to .zip
unzip the file
browse the package contents of the payload
look at the file called CodeResources inside the _CodeSignature directory and found the filename.
As soon as I put the string that matched the string in this file, the image showed up just as it should!
I have a problem reading a Strings file created dynamically inside my app's document directory.
Basically, I create and read my file using:
[[NSFileManager defaultManager] createFileAtPath:filePath contents:fileData attributes:nil];
NSLog(#"%#", [targetBundle localizedStringForKey:#"MY_STRING" value:#"#" table:#"test"]);
The file is created in the document directory, and the targetBundle also points to this directory.
The above code works very well when the strings file already exists in the document directory when the app runs.
So, if I delete the Strings file from the document directory, the NSLog displays: #.
When I run again the application (the file already exists), NSLog displays MY_LABEL's value.
I guess that the bundle loads its resources once at the launch, but how can I be sure to read my new file even if it has just been created?
Thank you for your help,
Julian
I didn't find how to reload a bundle but I fixed this problem by creating an empty file with the same name BEFORE the creation of the bundle.
With that, the bundle "knows" the file and if the file dynamically changes, the content is up-to-date (because the file is read at runtime).
I'm storing files in my application sandbox in a way that masks the original name of the file.
For example I have a file called abc.png which is stored in the sandbox as obfuscated.png.
When I do an open in of this file in another application using a UIDocumentInteractionController I'd like to have the other file open the file with the filename abc.png
Currently the other app opens the file as obfuscated.png.
I have tried changing the name property of the UIDocumentInteractionController in documentInteractionControllerWillPresentOptionsMenu as well as willBeginSendingToApplication, however in both cases the receiving application does not get the correct filename - it continues to show the obfuscated filename.
Apart from creating a copy of the file with the unobfuscated name, is there a way to make the receiving application use the desired filename?
Instead of a copy try:
NSError *error = nil;
[[NSFileManager defaultManager] linkItemAtPath:obfuscatedFilePath toPath:abcFilePath error:&error];
This will create a hard link to the file. Symbolic links will not work.
I've created 2 test applications:
In the one the documents are included into the bundle and can be opened by using the quick look controller.
In the other app, the documents are downloaded. When I try to open the files the quick-look controller simply shows a message saying an error occurred. Strangely it will open downloaded PDF documents without any problems.
I suspect it has something to do with headers and mime-types, but I'm not sure on this. Would anyone know what the reason could be that downloaded .doc or .docx documents won't open and local documents will?
It turned out to be a problem with saving the downloaded files. At first I was writing the data to a filepath URL. This saved the data to the right location, but the type of file wasn't recognized anymore.
The solution was to use the default FileManager to save the file.
[[NSFileManager defaultManager] createFileAtPath:filePath contents:data attributes:nil];