titanium ti.paint toimage() is returning {} after drawing on ios - titanium

the following code is resulting in to different outputs different android and ios. myBlob below is {} on ios - the image is empty even after drawing on the screen. in Android it an object with properties and is working fine, but iOS the image is always blank.
This was working before in past ios versions and builds so am I not building it right? We are using 5.3.0 GA for titanium SDK. I have the module checked for iOS in the TiApp Editor.
function uploadImage(signed) {
if (signed) {
var myBlob;
try {
myBlob = $.viewPaint.toImage();
var myImage = Titanium.Utils.base64encode(myBlob).toString();
$.nextAction.image = myImage;
} catch (ex) {
Titanium.API.error('FAILURE HANDLING SIGNATURE DOCUMENT: ' + ex);
return;
}
}
$.nextAction.perform(Alloy.Globals.requests);
}
Ti Paint Module for iPhone
#
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.4.0
apiversion: 2
architectures: armv7 i386 x86_64 arm64
description: Provides a paint surface user interface view.
author: Jeff Haynie
license: Appcelerator Commercial License
copyright: Copyright (c) 2010-2014 by Appcelerator, Inc.
# these should not be edited
name: paint
moduleid: ti.paint
guid: 43f13063-d426-4e9c-8a7a-72dc5e4aec57
platform: iphone
minsdk: 3.4.1.GA
prior code that adds execute to action object
var route = action.action.uri;
Ti.API.info('route = ' + route);
newAction.execute = function(requestManager) {
Titanium.App.fireEvent('app:index:view:requested',
controller : 'signscreen',
uri : route
});
};
code that fires the event to open:
Titanium.App.fireEvent('app:index:view:requested', {
controller : 'signature'
});

if you have anything in your view hierarchy that overlays your paintview such as a confirmation dialog or closing the view in a navigation controller and not grabbing your paintview prior to the window closing the paintview will always return empty. android will continue to work fine but ios will not as the view is not present in the view hierarchy.

Your console log value of {} is a red herring.
Tested on:
TiSDK 5.2.2.GA, 5.3.0.GA
ti.paint: 1.4.0, 1.4.1 (our version with fixes that have been ignored by appc)
With <run-on-main-thread>false</run-on-main-thread> in tiapp.xml
Using the example app.js from the module and adding the following:
var buttonSave = Ti.UI.createButton({ bottom:100, right:10, width:75, height:30, title:'Save' });
buttonSave.addEventListener('click', function(e){
var test = paintView.toImage();
console.log(test.length);
console.log(paintView.toImage());
var imageFile = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,"testing.png");
imageFile.write(paintView.toImage());
});
win.add(buttonSave)
You will find that
The logged value always will be {}
The length of the object you assigned toImage() to increases as you add pixels to your paintView
The image DOES get written to a file.

Related

branch io integration with Adobe air app issue

Our iOS app is live in iTunes, and we want to integrate it with Branch io. We can build the ipa for testing, but when we try to "Export Release Build", the Flash Builder 4.6 will hang.
This is the branch io guide that we are following:
https://dev.branch.io/getting-started/sdk-integration-guide/guide/adobe/
We just followed the steps, and put in the stuff up to step 4, where we called
branch.init() in the main class. The setting in branch io is setup ok.
here are the codes, (just copied from branch io's website)
// Then create a Branch instance:
var branch:Branch = new Branch();
// Register two events before initializing the SDK:
branch.addEventListener(BranchEvent.INIT_FAILED, initFailed);
branch.addEventListener(BranchEvent.INIT_SUCCESSED, initSuccessed);
private function initFailed(bEvt:BranchEvent):void {
trace("BranchEvent.INIT_FAILED", bEvt.informations);
}
private function initSuccessed(bEvt:BranchEvent):void {
trace("BranchEvent.INIT_SUCCESSED", bEvt.informations);
// params are the deep linked params associated with the link that the user clicked before showing up
// params will be empty if no data found
var referringParams:Object = JSON.parse(bEvt.informations);
//trace(referringParams.user);
}
// Initialize the SDK:
branch.init();
Any clues?

Map Plugin shows no service providers

I'm trying to render an empty Map in QML 5.7, in order to draw geolocated polylines. However, no plugins are available to supply the map data:
Map {
anchors.fill:parent
plugin: Plugin {
name: "osm"
Component.onCompleted: console.log('a',availableServiceProviders.length)
}
MapPolyline {
line.color: "#299FE7"; line.width: 3
path: parent.points
}
Timer {
running:true; interval:1000
onTriggered: console.log('b',parent.supportedMapTypes.length)
}
}
The above outputs:
qml: a 0
qml: b 0
Why don't I have any plugins available, and how can I get one to work?
You don't have a default provider because Qt does not enforce the usage of a specific one. Even more now that all of the available ones require a registration (and the acceptance of an agreement/ToS) to use their services.
The list of available plugins can be found here.
Following the links you can read about the specific setup for the usage of each one.
Adding a provider in QML is just a matter of declaring a Plugin type, something along the line of that:
Plugin {
name: <provider_name> // { "here" | "mapbox" | "osm" }
PluginParameter { name: <param_name>; value: <param_value> }
// other parameters
}
The very same task can be carried out in a C++/non-QML project via QGeoServiceProvider class.
Mind that the access to MapQuest changed few months ago, breaking the Open Street Map plugin. You now need credentials to access their service, e.g. read this comment. The relevant patch has been pushed and merged, as stated in the bug report page of last linked comment, and will be available in Qt 5.6.2 (and Qt 5.7.1) patch release.

Worklight 6.1: How to add EULA to hybrid app

Environment:
Worklight 6.1.0.2
dojo 1.9.4
We have created a hybrid app using Worklight 6.1 for android, iOS and windows8 platform. Now we would like to add and show End User License Agreement (EULA) window to the user, when the app first time launch. It should have Accept and Decline button. If user tap on Accept button, then he should be able to use the app.
I would like to know, how can we achieve this using Worklight 6.1.
Any help on this, will be much appreciated.
FYI there is nothing specific here to Worklight.
You could implement this in any number of ways w/out ever using any Worklight API whatsoever.
You could achieve it for example like this (untested code - you'll need to experiment):
In main.js create some global variable eulaAccepted:
var eulaAccepted;
// You will need to handle this property using HTML5 Local Storage so that it will persist for the next time the app is launched, and have the app act accordingly.
Then, in wlCommonInit():
function wlCommonInit() {
if (!eulaAccepted) {
displayEula();
} else {
displayApp();
}
}
In displayEula():
function displayEula() {
// either display a dialog using `WL.SimpleDialog`...
// Or maybe custom HTML with "accept" and "not accept" buttons
WL.SimpleDialog.show(
"Eula Agreement", "your-eula-text-here",
[{text: "Accept", handler: acceptEula },
{text: "Reject", handler: rejectEula}]
);
}
Handle the result:
function acceptEula() {
eulaAccepted = true;
... // Some code that will store the `eulaAccepted` variable using HTML5 Local Storage API
displayApp();
}
function rejectEula() {
// Display some other custom HTML instead of your app.
// Maybe also additional logic to try again to accept the Eula...
}

Worklight WL.TabBar does not display correct titles on iOS

I downloaded the IncludeExternalPages project from the getting started site. In the main.js for iPhone I can see what the WL.TabBar should display:
function wlEnvInit(){
wlCommonInit();
WL.TabBar.init();
WL.TabBar.addItem("WLtab1", function () {tabClicked(1); } ,"Home",{
image: "tabButton:Favorites"
});
WL.TabBar.addItem("WLtab2", function () {tabClicked(2); } ,"Client",{
image: "tabButton:Search"
});
WL.TabBar.addItem("WLtab3", function () {tabClicked(3); } ,"IBM",{
image: "tabButton:More"
});
WL.TabBar.setVisible(true);
WL.TabBar.setSelectedItem("WLtab1");
tabClicked(1);
}
However, when executing this code in a simulator the labels are Favorite, Search, and More instead of Home, Client, and IBM. I made no modifications to the project, just built it and ran on the iOS simulator. This was using WL6.2 with the 9/4 update (latest).
Any ideas why the titles are defaulting to iOS instead of what is specified in the code?
When using the "built-in" OS icons (Favorites, More, Search, ...) the tab item's title will default to that of the icon instead of the label in the code.
To change that, provide your own Favorites icon, for example, and then the "Home" label will be used.

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.