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
Contributor
oguzhancansever
Posts: 30
Registered: ‎12-18-2012
My Device: BB Z10, BBQ10 Dev Alpha C
Accepted Solution

Issue: String Encoding before invoking core apps

[ Edited ]

Hey folks

 

As I understood from the documentation string data used during invocation processes should be converted. Therefore I tried to convert my strings before invoking a core app. 

 

I tried following snippet according to http://developer.blackberry.com/html5/apis/blackberry.invoke.html 

but it didn't work.

 

var convertedStr = unescape(encodeURIComponent(unicodeStr));

 

 

 

Then I tried to fix it by another java script solution as seen below but this try was unsucessful too.

 

function utf8_encode(unicodeStr) {
string = unicodeStr.replace(/\r\n/g,"\n");
var utftext = "";

for (var n = 0; n < string.length; n++) {

var c = string.charCodeAt(n);

if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}

}

return utftext;
}

 

 

I didn't manage to show appropriate data in apps after invoking them. I have tested with calender, contacts and twitter app. Altough I got the correct strings in the console during debugging, strings didn't appear in apps properly.

 

I have used the following example for testing:

 

var string = "T & T’s “best”",
bb = blackberry.pim.contacts,
bbContact = bb.create();

 

bbContact.name = {
givenName: unescape(encodeURIComponent(string))
};

bbContact.save(function() {
console.log('Success');
}, function(error) {
console.log('Error:', error);
});


String shown in app: T & T’s “bestâ€Â

 

 

 

Has anyone the same issue?

 

Thanks in advance

-------------------------
@oggyindahouse
Please use plain text.
Retired
grahamzibar
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10

Re: Issue: String Encoding before invoking core apps

What character encoding have you given your app?  I usually use the following and it should help solve your issue:

 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

 

I belive MS Word's special quotes and apostrophe that are in your test string (they're not the standard html quotes and apostrophe) lie within the utf-8 character set so it would be wise to encode your app as such.

 

Hope that helps!  Let me know if you have more issues :smileyhappy:

------------------------------
@grahamzibar
-_- zZZ
Please use plain text.
Contributor
oguzhancansever
Posts: 30
Registered: ‎12-18-2012
My Device: BB Z10, BBQ10 Dev Alpha C

Re: Issue: String Encoding before invoking core apps

Thanks.

I have the same meta tag in the <head>. 

 

My problem is not that my app can not encode such character properly but rather the Blackberry apps self like contacts, calender etc.

-------------------------
@oggyindahouse
Please use plain text.
Retired
grahamzibar
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10

Re: Issue: String Encoding before invoking core apps

Hmmmmm I'll see what I can figure out today and give you a full answer later :smileyhappy:

------------------------------
@grahamzibar
-_- zZZ
Please use plain text.
Retired
grahamzibar
Posts: 71
Registered: ‎09-19-2012
My Device: No sleep til BlackBerry 10

Re: Issue: String Encoding before invoking core apps

I've built a sample app and I'm getting the same issue as you know matter what I try; it's definitely on the contact app's receiving end.  I think I'll file a bug report for this.  Thanks for finding this and I'll keep you posted!

------------------------------
@grahamzibar
-_- zZZ
Please use plain text.
Contributor
oguzhancansever
Posts: 30
Registered: ‎12-18-2012
My Device: BB Z10, BBQ10 Dev Alpha C

Re: Issue: String Encoding before invoking core apps

Thanks a lot for your effort.

Could you please mention in the bug description that it's not only an issue in contact app but also in calendar and twitter. Maybe also in other core apps so it would be meaningful to test it for all core apps.

 

Cheers

-------------------------
@oggyindahouse
Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 832
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Issue: String Encoding before invoking core apps

There was an issue logged and I believe a patch has been submitted. You could try calling atob(invocationData) to see if encoding as base64 makes it work.

Tim Windsor
Open Source Technical Lead
Please use plain text.
Contributor
oguzhancansever
Posts: 30
Registered: ‎12-18-2012
My Device: BB Z10, BBQ10 Dev Alpha C

Re: Issue: String Encoding before invoking core apps

[ Edited ]

Thanks for feedback.

I tried the following snippet and got a error object ,'Error: INVALID_CHARACTER_ERR: DOM Exception 5'

 

var string = "T & T’s “best”",

bb = blackberry.pim.contacts,

bbContact = bb.create();

 

bbContact.name = { givenName: atob(string) };

 

bbContact.save(function() { console.log('Success'); }, function(error) { console.log('Error:', error); });

 

Other foundations via steps:

 

1. I tried to catch the characters what might cause the problem and tried following line in the debug consolem when my app is on:

 

atob(encodeURI(btoa(x)))

 

THE OUTPUT: "T & T’s “best”"

 

2. When I try to escape the strange charackters:

 

escape(atob(encodeURI(btoa(x))))

 

THE OUTPUT"T%20%26%20T%E2%80%99s%20%E2%80%9Cbest%E2%80%9D"

 

3. I searched for  UTF-8 charackters and explored e.g. for %E2%80%99 :

   

 e2 80 99 stands for RIGHT SINGLE QUOTATION MARK

 

It is just the hex. value and UTF-8. So BB invocation framework may have problems with some UTF-8 characters?

-------------------------
@oggyindahouse
Please use plain text.
BlackBerry Development Advisor
twindsor
Posts: 832
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Issue: String Encoding before invoking core apps

Sorry, I wasn't sure if that would work, but thought it might be worth a shot.

 

There's a fix published on Github, but I don't know how comfortable you are in patching your WebWorks SDK with it.

 

This branch contains the fixed files for Contacts: 

https://github.com/blackberry-webworks/BB10-WebWorks-Framework/tree/fix-contacts-unicode

 

I don't know what all has changed in this branch though, so I don't know how safe it is to just use the whole thing. And you'll need to compile the extensions too, so you'd have to follow these instructions for building the framework:

 

https://github.com/blackberry-webworks/BB10-WebWorks-Framework/blob/fix-contacts-unicode/README.md

 

A new SDK is being worked on though, if you would rather wait. 

 

Tim Windsor
Open Source Technical Lead
Please use plain text.
Contributor
oguzhancansever
Posts: 30
Registered: ‎12-18-2012
My Device: BB Z10, BBQ10 Dev Alpha C

Re: Issue: String Encoding before invoking core apps

Do you know whether the new version of SDK is out?

-------------------------
@oggyindahouse
Please use plain text.