window.open addEventListener does not work on "Mobile Browser Simulator" - ibm-mobilefirst

I'm using IBM Worklight 6.2
I'm using window.open to load some external pages for OAuth and I configure event listeners for the opened window.
var authWindow = window.open(authUrl, '_blank', 'location=yes');
authWindow.addEventListener('loaderror', function(e) {
console.log(">> load error. event: " + JSON.stringify(e));
});
also for "load" and "loadstart" events.
This works in Android and iOS but when I preview the app in the "Mobile Browser Simulator" the eventListeners are not executed.
I have also tested creating a "desktopbrowser" application.
Any idea?

Loaderror, loadstart, and loadstop are specific to Cordova and not supported in the Mobile Browser Simulator. It would be best to test these on emulator or device. Please see: http://cordova.apache.org/docs/en/3.0.0/cordova_inappbrowser_inappbrowser.md.html#addEventListener

Related

How to enable Safari App Extension programmatically?

I'm developing a Safari App Extension inside a macOS app. When a user installs this app, the extension is added to Safari, but it's disabled by default. We can detect the state of extension by using SFSafariExtensionManager class via its getStateOfSafariExtension method.
Now I want to enable the extension state programmatically if it is disabled. How can I achieve that?
Or do anyone have any idea where the preferences / app extensions settings are stored in macOS?
You can create a button such as "Open extension preferences" to show Safari preferences directly for your extension then the user could enable it.
The code for your app:
import SafariServices
func enableExtension () {
SFSafariApplication.showPreferencesForExtension(withIdentifier: YOUR_EXTENSION_IDENTIFIER) { (error) in
NSLog("Error \(String(describing: error))")
}
}
SFSafariApplication could be used in Cocoa app only (not extension).

How to open url in default browser using titanium in Blackberry

I am currently working on a project in titanium .I wish to open url in default browser of BB10
simulator instead of webview used in the app on click event .I am using the following code
var win =Ti.UI.createWindow({
title:'Test'
});
var webview=Ti.UI.createWebView({
url:"http://demo.php.otssolutions.com/videoapp-uat/home"
});
win.add(webview);
webview.addEventListener('click',function(e){
var url=e.url;
Ti.API.info(url);
Titanium.Platform.openURL("http://demo.php.otssolutions.com/videoapp-uat/home");
});
win.open();
Thanks in advance for any help

What is the substitute for WL.App.close?

WL.App.close is deprecated. I know that this is not supported for iOS. But why is it deprecated for Android as well? At the moment, it is still functioning fine, even on 6.2, but since it is deprecated, what is the alternative/substitute for this?
In Android as well, this is not the recommended approach. You should let the user quit the app, and this is done by manually bringing up the "applications view" and swiping the app in order to quit it.
Can be corroborated by these answers by Googlers:
http://android.nextapp.com/site/fx/doc/exit
Additionally, there are these approaches:
Close application and launch home screen on Android
https://groups.google.com/forum/#!topic/android-developers/Y96KnN_6RqM
You could write a Cordova plug-in that will force-quit the app and trigger it by overriding whatever you'd like (like the Back button), or create a dedicated Quit button, etc.
In MobileFirst 7.0, this method seems to be deprecated in both iOS and Android, but when I call this "deprecated" method in Android, it really works.
I think overriding Android's back button might be a best practice in Android webapp as back button may cause strange page navigating issues (if you use UI frameworks like JQM). This is what I done in WL's main.js.
WL.App.overrideBackButton(backFunc);
function backFunc(){
WL.SimpleDialog.show(
"Alert",
"Sure to quit the app ?",
[ {text : 'Cancel', handler: function() {
}},
{text : 'Yes', handler: function() {
if(WL.Client.getEnvironment() == WL.Environment.ANDROID) {
WL.App.close();
}
}}]
);
}

worklight fail to require DOJO Combobox on real device -fail to load ... /dijit/form/nls/it/ComboBox.js

Dojo 1.8
Worklight 5.0.6
On Browser and android emulator all works, but if I execute the app on real the parse didn't works.
This is Dojo.js
function dojoInit() {
require([ "dojo",
"dojo/parser", "dojox/mobile", "dojox/mobile/compat",
"dojox/mobile/ScrollableView",
"dojox/mobile/ScreenSizeAware",
"dojox/mobile/FixedSplitter",
"dojox/mobile/Container",
"dojox/mobile/ComboBox"
],
function(dojo) {
dojo.ready(function() {
});
});
}
This is browser's error on tablet:
xxx.26.81:8080/apps /services/preview/AcgTablet/common/0/default/dijit/form/nls/it/ComboBox.js Error dojo.js:26
but this error doesn't appear on pc browser
But there are in the folder!
You are probably using Worklight V6?
There is an issue currently to run on Android devices. You can find the workaround here: Worklight core-web-layer.js errors
For your issue with running on Android, if you're using Worklight 6.0 with a new project, copy the following files from the Dojo Library project that was created alongside the Worklight project:
toolkit/dojo/dojo/nls/core-web-layer_ROOT.js
toolkit/dojo/dojo/nls/mobile-ui-layer_ROOT.js
These files then must be added to your Worklight project's www/dojo/nls/ directory.
In addition to including the *_ROOT.js files, you may also need to remove the development configuration from the application. To do this, open the Console view (Window > Show View > Other... > Console). From the Console view, click the Open Console button and choose Dojo Library Requests from the list. From the Dojo Library Requests console, click the View Menu (the triangle in the toolbar), and uncheck Provide Library Resources. After this, build and deploy your application to your emulator or device.
have you try doing it this way?
function dojoInit() {
require(["dojo/ready",
"dojox/mobile/parser",
"dojox/mobile",
"dojox/mobile/compat",
"dojox/mobile/ScrollableView",
"dojox/mobile/ScreenSizeAware",
"dojox/mobile/FixedSplitter",
"dojox/mobile/Container",
"dojox/mobile/ComboBox",
"dojo/ready!"
],
function(ready,parser,Container,ComboBox) {
ready(function() {
alert("I was clicked");
});
// Parse the page for widgets!
parser.parse();
});
Regards

IBM Worklight 6.0 - Cordova camera simulation in the Mobile Browser Simulator doesn't work

My camera code was working fine in WL 5.0.6 and the mobile browser simulator would correctly display the image. Now I moved to WL 6.0 andI get the following error when using the preview in the Mobile Browser Simulator and using the Cordova camera simulation to get a fake picture.
I am using Chrome for the preview.
Not allowed to load local resource: file:///C:/Users/Administrator/cordova/internal/sim/camera/camera1_m.jpg wljq.js:2374
The code is similar to this
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.FILE_URI });
Note that if I use the DATA_URL, it seems OK with the mobile browser simulator. Just the FILE_URI doesn't seem to be working with the mobile browser simulator.
The Worklight 6.0 Mobile Browser Simulator supports Cordova 2.6 APIs. For navigator.camera.getPicture the following destination types can be used in WL 6.0:
Camera.DestinationType = {
DATA_URL : 0, // Return image as base64 encoded string
FILE_URI : 1, // Return image file URI
NATIVE_URI : 2 // Return image native URI (eg. assets-library:// on iOS or content:// on Android)
};
Example:
navigator.camera.getPicture(
function(data) {
document.getElementById('camera_status').innerHTML = "Success: picture located at " + data;
var img = document.getElementById('camera_image');
img.style.display = "none";
},
function(e) {
console.log("Error getting picture: " + e);
document.getElementById('camera_status').innerHTML = "Error getting picture.";
},
{ quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI, sourceType: navigator.camera.PictureSourceType.SAVEDPHOTOALBUM, encodingType: fileType});
Try clearing your browser cache and then be sure to accept the applet permission dialogue on Mobile Browser Simulator startup. Also make sure that your file permissions will allow transfer from the C:/Users//cordova/internal/sim/camera/ folder as that is where the applet stores the camera sim image content.
Cordova 2.6 Camera API reference:
http://docs.phonegap.com/en/2.6.0/cordova_camera_camera.md.html
Funny, that there is already a troubleshooting document for your problem.
http://www-01.ibm.com/support/docview.wss?uid=swg21614861
It looks like DATA_URL didnt work in WLv5, while (if you are right) FILE_URI is not working since WLv6.