how can I change in Xcode this line
NSString *filePath = [[NSBundle mainBundle] pathForResource:(#"%#",[command.arguments objectAtIndex:0]) ofType:#"pdf"];
to look in Phonegap (cordova) file structure for the PDF like:
~/Library/Caches
or
~/Docuemnts
I don't have a definite answer for you, but I believe the cordova-plugin-file plugin is where the answer will be found. I have only limited experience with it, but it looks like you would be looking for the following paths:
cordova.file.cacheDirectory = '~/Library/Caches'
cordova.file.documentsDirectory = '~/Documents'
From the cordova documentation, it looks like you'll be trying to get a DirectoryEntry from the window object, and then use a DirectoryReader to iterate over the contained files. There may be a search, but I don't know the API well enough beyond the basics.
var bundleDocs = window.resolveLocalFileSystemURL(cordova.file.documentsDirectory);
var bundleDocsReader = bundleDocs.createReader();
bundleDocsReader.readEntries(
function success(files) { // iterate over files and do stuff },
function error(err) { // respond to error }
);
Hope that helps!
NOTE: The direct API references for DirectoryEntry and DirectoryReader link to the Cordova 3.0 documentation because the Cordova 5.1 documentation for plugins is awful.
Related
My problem:
I have a zip file that contains a firmware update for my company's device
I want to be able to access it using react-native-fs with the code below
.
export function readAssetFile(name) {
if(Platform.OS === 'ios') {
return RNFS.readFile(`${RNFS.MainBundlePath}/assets/data/${name}`);
} else {
return RNFS.readFileAssets(`raw/${name}`, 'base64');
}
}
My project structure looks like:
ProjectDir
android
data
image1.png
image2.png
firmwarefile.zip
ios
The android branch works, because I added a build step in my .gradle to copy firmwarefile.zip into ProjectDir/android/app/src/main/assets/raw. So I can call readAssetFile('firmwarefile.zip'), and it returns the data.
On iOS, all the image files (Image1.png, Image2.png) are included in MyProject.app/assets/data/ without me having to do anything, but the zip file that sits beside them is not.
Looking into the actual packager code (from the metro project), it seems (based on metro/src/defaults.js) that zip files aren't included by default by the packager, but the packager can be configured to include other file types. But I can't find any documentation for how I'd go about doing that configuring.
Sorry for what feels like a really simple question, but I've been trying to get this zip included in my bundle for ~4 hours now. I'm resorting to manually putting in console.logs and error-throws to trace things inside metro to try and find where I should be sending in my config.
Versions:
React-native: 0.55.3
Metro: 0.30.2
This is a hack, but it gets it done:
Convert your zip binary to a base64 string
Stick it in a .js file, a la module.exports = "<your base64 data goes here>"
In your file that needs the zip file, use import myZipFileAsBase64 from './hacky-base64-file.js';
Here's a quick script to make your base64 files:
var fs = require('fs');
function prepareZip(file, outJs) {
const b64 = fs.readFileSync(file, 'base64');
fs.writeFileSync(outJs, `module.exports = ${JSON.stringify(b64)};`);
}
prepareZip('./data/myFirmware.zip', './hacky-base64-file.js');
im working in a mobilefirst adapter (6.3) that need to pass an image from an url that is in the internarl network file system(example :http://www.up.edu.pe/RED_Compartir/facebook.png) but i cant get the data correctly, the img data isnt in the text variable:
Here is my server side code:
function getImage(id){
var input = {
method : 'get',
returnedContentType : 'plain',
path : '/someUrl/someUrl2/'+id+'.jpg'
};
return {
out: Base64.encode(WL.Server.invokeHttp(input).text)
};
}
Here is my client code to process de image:
function getImageFrom() {
execMobileFirstAdapter("adapterName", "method", ["parameter"]).then(function (data){
WL.Logger.debug("OK")
var imageBase = data.invocationResult.out;
document.getElementById('imageServer').setAttribute( 'src', 'data:image/jpeg;base64,'+ imageBase );
}).fail(function(data){
WL.Logger.debug("error");
})
}
Is there a way to return the base64 from a jpg image from a mobilefirst adapter?
Ive used this example:
https://www.ibm.com/developerworks/community/blogs/mobileblog/entry/ibm_worklight_adapter_accessing_an_image?lang=en
and Works perfectly but i need to do this only with JavaScript in the server. is this posible?
Is there a way to return the base64 from a jpg image from a
mobilefirst adapter?
I've used this example:
https://www.ibm.com/developerworks/community/blogs/mobileblog/entry/ibm_worklight_adapter_accessing_an_image?lang=en
and Works perfectly but i need to do this only with JavaScript in the
server. is this possible?
The easiest approach is in fact to implement it the way the example does it in the article you've provided.
The only other way is to find a JavaScript lib that does base64 encoding and try to add this lib to the adapter and then use it.
Note that JavaScript adapters do not support adding additional files to the adapter, so that means you need to take the entire implementation of whichever lib you'll find and put it inside your adapter code. Not so nice. Also does not guarantee it'll work.
Additionally, are you calling your adapter from inside a Cordova plug-in? That was strange. Why? Why not just use the WL.Client.invokeProcedure API... just like in the article...
I wasn't able to find anything online about this, but LSSetDefaultHandlerForURLScheme will return -54 when the sandbox is enabled. I'm not sure what entitlement needs to be turned on for this to work as it does without the sandbox on.
To see this in effect, create a new project with this in the appdelegate:
-(void)applicationWillFinishLaunching:(NSNotification *)notification {
// Become default handler
CFStringRef bundleID = (CFStringRef)CFBridgingRetain([[NSBundle mainBundle] bundleIdentifier]);
OSStatus result = LSSetDefaultHandlerForURLScheme(CFSTR("maxel"), bundleID);
if (result != 0) {
assert(0);
}
}
It will work. Next turn on sandbox. It will fail with -54 in result.
Built on OSX 10.10 Yosemite. Anyone else run into this?
According to Apple's developer forums, you can't do this anymore in the sandbox--the behavior you are seeing is expected. It's really aggravating, because no alternative API exists to implement this functionality, short of stepping outside of the sandbox.
I am using dojo i18n:
dojo.requireLocalization("scripts", "scprop");
var nls = dojo.i18n.getLocalization("scripts", "scprop");
to get text from nls.keyname and it is working fine.
When resource bundle changed (adding/removing keys), new bundle is not loading - still loading old bundle from cache. How to reload the new bundle. Please suggest.
I modified the dojo source code to fix this. This was done on the 1.8.x codebase. Not sure what the 1.9.x codebase looks like.
dojo/i18n.js ~line 444
// MODIFIED: append a query parameter to handle caching of
// modules/resource bundles by product version
var modUrl = url + '?dojo.cache=' +
encodeURIComponent(dojo.config.loadURIVersion || dojo.version.revision);
// ****************************************************************************
xhr.get({
url:modUrl, // MODIFIED
sync:true,
load:load,
error:function(){
results.push(cache[url] = {});
}
});
How to know the contents of NSbundle in XCode Porject??
bcoz issue is, I have placed a config.doc file in resource folder of my XCode project and i want to read the contents of that config.doc file, but it says that config.doc file is not found. How to solve this problem??
This is how my code looks like:
-(void)applicationDidFinishLaunching:(UIApplication*)application
{
if([NSBundle mainBundle]pathForResource;#"config" ofType:#"doc")!=nil)
{
NSLog(#"File Exists");
}
else
{
NSLog(#"File not found!!");
}
NSString *configContents = [[NSBundle mainBundle]pathForResource:#"config" ofType:#"doc"];
NSLog(#"Contents of config file : %#",configContents);
}
OUTPUT :
File not found!!
Contents of config file :(null)
how to solve this problem?? i'm not able to make where is the mistake..
plz help
Thank You
You can see the contents of the bundle in the following way :
Expand the "Products" group in xcode
Right click on your_prodcuct.app and click "Reveal in Finder"
In finder right click on your app and click "Show package contents"
Now you can check whether the file actually exists in the bundle or not.