Titanium iOS App crashes after taking 25+ images with the camera - appcelerator

I am working on titanium app that is using camera for taking pictures. After taking around 15+ pictures the app will crash. I found the same problem reported on Appcelerator Titanium side https://jira.appcelerator.org/browse/TIMOB-24389, https://jira.appcelerator.org/browse/AC-6225 but I cannot see a solution there. I tried what is suggested there but that is not fixing the problem.
Here is also some simple app.
Steps:
1.Click "Add photo" button
2.Take picture
3.Click "Use Photo"
4.Repeat steps 15+ times.
App crashes during the process of taking picture.
Tested with different devices and different Titanium SDKs, it can be reproduced every time.
var win = Ti.UI.createWindow({});
var view = Ti.UI.createView({});
var button = Ti.UI.createButton({
color : '#000000',
title : "Add photo",
height : 'auto',
width : 'auto'
});
view.add(button);
button.addEventListener('click', function(e) {
showCamera();
});
function showCamera() {
Titanium.Media.showCamera({
showControls : true,
mediaTypes : [Ti.Media.MEDIA_TYPE_PHOTO],
autorotate : true,
success : function(event) {
},
error : function(error) {
},
cancel : function() {
}
});
}
win.add(view);
win.open();
Does anyone know some workaround how can I avoid this crashing?
Thanks.

I used to have this SAME issue for a long time.
For iOS, you’ll need to set the <use-jscore-framework> flag to true in the tiapp.xml file.
This flag is enabled by default in Titanium SDK 7.0.0 and later.
https://jira.appcelerator.org/browse/TIMOB-24206

Related

tabs onUpdated event not detected on Safari extension?

I am trying to develop a simple web extension/addon under Safari, which is using the tabs onUpdated event. I used the Safari XCRUN converter: https://developer.apple.com/documentation/safariservices/safari_web_extensions/converting_a_web_extension_for_safari
What I am trying to do is :
Open new tab on Google Scholar with set prefs params, from "options.js" script (Options page code below)
Listen for this tab to be updated and ready (e.g. tab status is complete)
Then, inject a content script that will simulate the user click on save button (i.e. on GScholar page)
Then remove the listener, and wait 1,5s (for GS tab to reload and finish saving) in order to finally close this tab.
// Detect browser language
const gsUrl = currentBrowser.i18n.getUILanguage().includes("fr")
? GSCHOLAR_SET_PREFS_FR_URL
: GSCHOLAR_SET_PREFS_COM_URL;
// Listener to detect when the GS tab has finished loading
const gsTabListener = (tabId, changeInfo, tabInfo) => {
if (changeInfo.url && changeInfo.url.startsWith(GSCHOLAR_HOST)) {
currentBrowser.tabs.executeScript(
tabId,
{
code: `document.getElementsByName("save")[0].click();`,
},
() => {
currentBrowser.tabs.onUpdated.removeListener(gsTabListener);
setTimeout(() => currentBrowser.tabs.remove(tabId), 1500);
}
);
}
};
currentBrowser.tabs.onUpdated.addListener(gsTabListener); // Add tab listener
currentBrowser.tabs.create({
url: `${gsUrl}?inst=${gScholarInstIdList.join("&inst=")}&save=#2`,
active: false,
}); // Open GS tab according to browser language
The problem is that it works well on Chrome/Edge/Firefox (on MacOS), but not on Safari : the GS tab is opended but isn't closed and nothing happens :-/
PS:
It seems tabs onUpdated event is well supported on Safari according to MDN.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/onUpdated
I have also tried webNavigation onCompleted event, but same !
Developing on : MacBookAir under MacOS Monterey 12.4, Safari 15.4 (17613.2.7.18), XCode 13.3.1 (13E500a), extension is bundled with Webpack 5.68.0 (e.g. building all assets files).
I really don't see what I am doing wrong and why wouldn't this tab event be intercepted ?
Thanks for your feedback.
After debugging I finally sloved this by noticing that in fact the events were triggered, but missed because of the availability and values of parameters passed into callabck (changeInfo, details) depending on the browser we're on.
So I switched from onUpdated to webNavigation.onCompleted API, which is better suited to our need (tab page fully loaded) and whose parameter is simple and consistent across browsers :-)
const uiLanguage = currentBrowser.i18n.getUILanguage().includes("fr")
? "fr"
: "com"; // Detect browser language
const gsUrl = `${GSCHOLAR_SETTINGS_HOST}.${uiLanguage}`;
// Listener to detect when the GS tab has finished loading
const gsTabListener = (details) => {
if (details && details.url && details.tabId) {
if (details.url.startsWith(`${gsUrl}/scholar_settings?`)) {
currentBrowser.tabs.executeScript(details.tabId, {
code: `document.getElementsByName("save")[0].click();`,
});
} else if (details.url.startsWith(`${gsUrl}/scholar?`)) {
currentBrowser.webNavigation.onCompleted.removeListener(
gsTabListener
);
currentBrowser.tabs.remove(details.tabId);
}
}
};
currentBrowser.webNavigation.onCompleted.addListener(gsTabListener); // Add GS tab listener
currentBrowser.tabs.create({
url: `${gsUrl}/scholar_settings?inst=${gScholarInstIdList.join(
"&inst="
)}&save=#2`,
active: false,
}); // Open GS tab according to browser language

Horizontal scrolling issue using angularjs-dragula

I am using angularjs-dragula and I am not able to auto scroll to the overflow container that is hidden from the screen.
This is my issue:
I have five containers in my dragula and the 5th container is hidden from the screen. Now I want to drag an element from the first container and drop it in the 5th container. But I am not able to do this, since the screen is not auto scrolling to the 5th container.
Does angularjs-dragula support vertical scrolling? or is there a property that I'm missing?
Example Plunkr : https://plnkr.co/edit/iD38MugmHIx298p7OlrI?p=preview
var app = angular.module('angular-dragula-demo', [angularDragula(angular)]);
app.controller('MainCtrl', function($scope, dragulaService) {
dragulaService.options($scope, 'fifth-bag', {
copy: true
});
});
It seems like this option is not implemented in Dragula. Dragula's developer suggests to use the module dom-autoscroller.
See this issue on Github: https://github.com/bevacqua/dragula/issues/121
To implement this functionality with AngularJS:
1) Download dom-autoscroller from the official repo: https://github.com/hollowdoor/dom_autoscroller/blob/master/dist/dom-autoscroller.min.js
2) Include it in your project folder
3) Enable autoscroll in your controller:
// ENABLE AUTOSCROLL FOR GOALS LIST
var scroll = autoScroll([
document.querySelector('.list')
], {
margin: 30,
maxSpeed: 10,
scrollWhenOutside: true,
autoScroll: function () {
//Only scroll when the pointer is down
return this.down
}
});

iPad PhoneGap map not showing

I have the following html;
<div id="map_canvas"></div>
and if have some js;
document.addEventListener("deviceready", onDeviceReady, true);
function onDeviceReady () {
navigator.notification.alert("Yup, it works!",function(){},"","");
navigator.geolocation.getCurrentPosition(getCurrentPositionSuccess, getCurrentPositionError);
};
function getCurrentPositionSuccess(position) {
alert(123);
//alert(position.coords.latitude);
currentPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
gmap = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: 15,
center: currentPosition,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}
Obviously all the above is a snip but all the key players are in place.
All this worked great on my PC and using Safari. However, when I moved over to the mac, xcode and phonegap, the map no longer displays.
alert(123) never happens and the getCurrentPositionError function is called.
The error is code 2, kclerrordomain error 0
I get the alert that the app want's to use my location though.
Any help here would be great.
I am using xcode 5.0.1 on Mavericks with phonegap 3.1 for iPad.
edit
If I use the Retina simulator I can get back the location but not if i use the ipad sim. Why would that be?

changing Firefox addon sdk toolbarbutton icons at runtimes

I'm using the toolbarbutton library, because the normal widgets would not store their positions if I restart Firefox.
Unfortunately I want to change the icon on runtime. With the widgets I did:
widget.contentURL = "http://127.0.0.1:8082/static/icons/eth_16.png";
With the toolbarbuttons I tried:
Toolbarbutton.image = "http://127.0.0.1:8082/static/icons/eth_16.png";
without any effect. The image seems to be only used when construction the toolbarbutton.
Also tried to destroy and recreate the button with a different icon, but that causes annoying flickering.
Any idea would be appreciated.
I did a quick test and this should work as expected so I'm not sure what issue you're running into here. Here's some example code that works just fine:
var toolbarbutton = require("toolbarbutton");
var timer = require("timer");
var TEST_ICON_M_URL = "http://www.mozilla.org/media/img/favicon.png";
var TEST_ICON_G_URL = "http://www.google.com//images/google_favicon_128.png";
console.log("TEST_ICON_URL", TEST_ICON_M_URL);
var options = {
id: "test-tbb",
label: "TEST BUTTON",
toolbarID: "nav-bar",
image: TEST_ICON_M_URL,
forceMove: true
};
var tbb = toolbarbutton.ToolbarButton(options);
tbb.moveTo(options);
timer.setTimeout(function () {
tbb.image = TEST_ICON_G_URL;
console.log("switched", TEST_ICON_G_URL);
}, 5 * 1000); // 5 seconds
Is there more code you could post? The problem must be somewhere else.

Appcelerator. Using swipe to open window

I am developing an iOS app in Appcelerator and I want to switch between windows with the use of a swipe event listener. How can I do this? The below code does not work. The current window that I "start" from contains a table.
var window = Ti.UI.currentWindow;
window.addEventListener('swipe', function() {
// Create the new window
var win = Titanium.UI.createWindow({
title: 'Contacts',
url:'contacts_simple.js'
});
// Animate the page turn
Titanium.UI.currentTab.open(win, {animated:false});
});
I think the problem is with the Ti.UI.currentWindow. Depending on the context you're working in it may not be valid.
Google 'appcelerator currentWindow', but here's a related link:
http://developer.appcelerator.com/question/5391/currentwindow
This will not be optimal and dynamic, but to start with, try referencing the window implicitly. Meaning if you did something like
var window_x = Ti.UI.createWindow({});
try
window_x.addEventListener('swipe', function() {...});

Resources