Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 185
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone
Accepted Solution

Webworks 2.0 gold and webkitRequestFileSystem for write a file don't works

[ Edited ]

Is there some problem with webworks 2.0 Gold with webkitRequestFileSystem for write a file?

 

This code works fine on WebWors 1.0, now with 2.0 Gold OnInitFsWrite is not executed.

 

blackberry.io.sandbox = false;
window.webkitRequestFileSystem(PERSISTENT, 1024 * 1024, onInitFsWrite, errorHandler);


function onInitFsWrite(fs) {
	
....

 

And of course i added:

- access_shared permit on config.xml

- and plugin com.blackberry.io 

 

Thanks in advance.

Josep Maria
Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Webworks 2.0 gold and webkitRequestFileSystem for write a file don't works

Hi,

 

Did you add the com.blackberry.io plugin?

 

webkitRequestFileSystem is actually built into the device webview and does not ship as part of the SDK

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Developer
Posts: 185
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone

Re: Webworks 2.0 gold and webkitRequestFileSystem for write a file don't works

Yes i added com.blackberry.io plugin (just updated my question few moment ago)

Josep Maria
Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Webworks 2.0 gold and webkitRequestFileSystem for write a file don't works

It would help if you could post the entire HTML page.

 

The snippet you posted works correctly for me given that you wait for the "deviceready" event and errorHandler exists.

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Highlighted
Developer
Posts: 185
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone

Re: Webworks 2.0 gold and webkitRequestFileSystem for write a file don't works

[ Edited ]

Yes I am wait for the "deviceready" event and errorHandler exists.

 

Let me try to investigate what's happening, because in home page this code it's not working, and in other page it's working fine, but in console not appears any error Smiley Sad

 

Thanks for you support Bryan.

Josep Maria
Developer
Posts: 185
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone

Re: Webworks 2.0 gold and webkitRequestFileSystem for write a file don't works

Just found what is happening.

 

I have a bbui page like this:

 

<div data-bb-type="menu">
	<div data-bb-type="menu-item" data-bb-img="images/backup.png" onclick="Backup();">Backup on Menu</div>
</div>
<div data-bb-type="round-panel"> 
	<div data-bb-type="row">
		<div data-bb-type="label">Backup:</div>
		<div data-bb-type="button" onclick="Backup();">Backup Button</div>
	</div>
</div>

<div data-bb-type="action-bar" id="menu">
	<div onclick="Backup();" data-bb-type="action" data-bb-style="button" data-bb-img="images/icons/welcome.png">Backup Action Bar</div>
	<div onclick="Backup();" data-bb-type="action" data-bb-style="button" data-bb-overflow="true" data-bb-img="images/icons/welcome.png">Backup Overflow</div>
</div>

 

 an in my app i have this plugins added:

 

com.blackberry.app
com.blackberry.io
com.blackberry.ui.dialog
com.blackberry.ui.toast

 javascript code:

 

function Backup() {
	showCustomToast('Backup started!!', '');
	blackberry.io.sandbox = false;
	window.webkitRequestFileSystem(window.PERSISTENT, 1024 * 1024, onInitFsWriteBackup, errorHandler);
}

function onInitFsWriteBackup(fsBackup) {

		console.log('onInitFsWriteBackup');
	var sFile = "Backup.txt";
	sPath = '/accounts/1000/shared/';
	
	fsBackup.root.getFile(sPath + 'documents/' + sFile, {create: true}, function(fileEntry) {

		// Create a FileWriter object for our FileEntry (log.txt).
		fileEntry.createWriter(function(fileWriter) {

			fileWriter.onwriteend = function(e) {
				showCustomToast('Backup completed!!\nSaved on Destination: \n\nFile name:\n\n' + sFile, '');
			};

			fileWriter.onerror = function(e) {
				blackberry.ui.dialog.standardAskAsync('Exception doing a Backup: ' + e.name + '; ' + e.message, blackberry.ui.dialog.D_OK, standardDialogCallBack, _ops);
			};

			// Create a new Blob and write it to log.txt.
			var esBlob = new Blob(['Backup'], {
				type : 'text/plain;charset=UTF-8'
			});
			fileWriter.write(esBlob);
			

		}, errorHandler);

	}, errorHandler);

}

function errorHandler(e) {
	var msg = '';

	switch (e.code) {
		case FileError.QUOTA_EXCEEDED_ERR:
			msg = 'QUOTA_EXCEEDED_ERR';
			break;
		case FileError.NOT_FOUND_ERR:
			msg = 'NOT_FOUND_ERR';
			break;
		case FileError.SECURITY_ERR:
			msg = 'SECURITY_ERR';
			break;
		case FileError.INVALID_MODIFICATION_ERR:
			msg = 'INVALID_MODIFICATION_ERR';
			break;
		case FileError.INVALID_STATE_ERR:
			msg = 'INVALID_STATE_ERR';
			break;
		default:
			msg = 'Unknown Error';
			break;
	};

	blackberry.ui.dialog.standardAskAsync('Error: ' + msg, blackberry.ui.dialog.D_OK, standardDialogCallBack, _ops);

}


function showCustomToast(sMessage, sText) {
	var message = sMessage, buttonText = sText, toastId, onButtonSelected = function() {

	}, onToastDismissed = function() {

	}, options = {
		buttonText : buttonText,
		dismissCallback : onToastDismissed,
		buttonCallback : onButtonSelected,
		timeout : 2000
	};

	toastId = blackberry.ui.toast.show(message, options);
}

 

An after 1000 test i found that exist on Webworks SDK a conflic with com.blackberry.io, com.blackberry.app and when o click on "Backup on Menu" and "Backup Overflow" options.

 

With "Backup Button" and "Backup Action Bar" click,  Backup() function works fine.

 

But on menu-item  "Backup on Menu" and data-bb-overfow "Backup Overflow" Backup() function is not executing correctly, onInitFsWriteBackup it's not firing and not appears an error on Console.

 

If I remove com.blackberry.app backup() function works fine too on click "Backup on Menu" and data-bb-overfow "Backup Overflow"

 

Thanks in advance for your help

Josep Maria
Developer
Posts: 185
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone

Re: Webworks 2.0 gold and webkitRequestFileSystem for write a file don't works

Hi Brian take a look on my last message, seems exist a conflict with com.blackberry.io and com.blackberry.app in WebWorks SDK 2.0. All the best
Josep Maria
Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Webworks 2.0 gold and webkitRequestFileSystem for write a file don't works

Hi,

 

It seems like this may be a bbUI issue rather than WebWorks. I tried the same code you provided and it worked for me although the menus were not rendering properly.

 

I'd recommend distilling this down to the smallest possible code sample and posting it to the bbUI issues list:

 

https://github.com/blackberry/bbUI.js/issues

 

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins
Developer
Posts: 185
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone

Re: Webworks 2.0 gold and webkitRequestFileSystem for write a file don't works

[ Edited ]

Hi Bryan, thaks for your response.

 

Just forked BB10-WebWorks-Samples / BfB-Boilerplate-bbUI.js-0.9x and added a new page backup.html and added webkitRequestFileSystem javascript code on js/app.js file.

 

and added webworks plugin: com.blackberry.app, com.blackberry.io and com.blackberry.ui.dialog

 

and run webworks run, and I have same issue.

 

you can download from my repository this minimal modification: https://github.com/miamon/BB10-WebWorks-Samples/tree/master/BfB-Boilerplate-bbUI.js-0.9x/

 

and see difference betwwen Master here: https://github.com/miamon/BB10-WebWorks-Samples/compare/blackberry:master...master

 

So .... I think it's not a javascript issue.

 

in any case I opened a bbUI.js issue: https://github.com/blackberry/bbUI.js/issues/1012

 

All the best

 

 

Josep Maria
Retired
Posts: 203
Registered: ‎12-18-2012
My Device: Z10, Q10, Q5, Z30, Z3
My Carrier: Bell

Re: Webworks 2.0 gold and webkitRequestFileSystem for write a file don't works

Thanks, that was helpful. I can reproduce it now.

 

Please try this workaround

 

function Backup() {
	showCustomToast('Backup started!!', '');
	blackberry.io.sandbox = false;
        window.requestAnimationFrame(function () {
	    window.webkitRequestFileSystem(window.PERSISTENT, 1024 * 1024, onInitFsWriteBackup, errorHandler);
        });
}

 

Bryan Higgins
BlackBerry WebWorks
@bryanhiggins