How can I call the Blackberry API for a hosted webapp WebWorks?

32 Views Asked by At

I am now using WebWorks to make a hosted web app, i.e. an app that open my website url. I also want to include some native Blackberry API functions (e.g. Toast) to the app.

Everything was working fine. I include my URL (for example, http://www.example.com/index) in the "Main URL" field. And on my site, I have added the line

So it can load the cordova.js and use the blackberry functions.

But if I change my "Main URL" to https like https://www.example.com/index, the cordova.js can't be loaded anymore. On the web inspector console, it says

 [blocked] The page at https://www.example.com ran insecure content from local:///cordova.js.

I have tried to add local:/// to the whitelist, and turn the "Enable Web Security" off, but to no avail.

Please advice what I can do. Thank you very much!

1

There are 1 best solutions below

0
gmm900913 On

This is the first post of mine (also new to BB dev) so suggest if anything is not correct and accept my sincere appologies. I am giving you step by step I hope you don't get offended as others who are new to BB dev see this as helpful for them.

Step 0: Start the "BlackBerry 10 Simulator".
Step 1: Start the "BlackBerry WebWorks 2.2.0.15"
Step 2: Opens the browser with localhost:3123/
Step 3: Create a sample project by giving Create Project PROJECT ID PROJECT NAME PROJECT PATH
Step 4: This would create a project with index.html file
Step 5: Click on plugins tab on the browser with localhost:3123 and add "com.blackberry.invoke"
Step 6: Replace the body section of code of index.html with the code mentioned below:-

<body>
    <div class="app">
        <a onclick="openWebLink()"> Click me to test Opening https </a>
        <div id="deviceready" class="blink">
            <p class="event listening"> </p>
            <p class="event received"> </p>
        </div>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();

        function onInvokeSuccess() {
            console.log("Invocation successful!");
            location.href = "https://www.hsbc.co.uk/1/2/";
        }

        function onInvokeError(error) {
            console.log("Invocation error!");
        }

        function openWebLink() {
            blackberry.invoke.invoke({
                uri: "https://www.hsbc.co.uk/1/2/"
            }, onInvokeSuccess, onInvokeError);
        }
    </script>
</body>

Step 7: Click on build tab on the browser
Choose Build Mode : DEBUG MODE and Target Type : SIMULATOR
Step 8: Click on build and install. Once ready opens the app on the simulator and prompts with OK button click on it.
Step 9: Again click on "Click me to test Opening https" it opens a browser with secure url
Step 10: If this works for you might give you a hint on how you want to proceed.