pause and resume listeners not working in phonegap on iOS4.3 and iOS 5 - iphone

I was making a native app in iPhone4 with iOS 4.3
in my Body onLoad i m adding
document.addEventListener("pause", Game.prototype.pauseListener.bind(this), false);
document.addEventListener("resume", Game.prototype.resumeListener.bind(this), false);
and in that same file i m writing a function
Game.prototype.resumeListener= function()
{
console.log("in resumeListener");
this.PauseGame(false);
}
Game.prototype.pauseListener= function()
{
this.PauseGame(true);
}
this code is working perfectly fine in Android and when i manually minimise the app, but when the application is interrupted by a voice incoming call the application dont pause.
Basically Pause and Resume event are not fired.
I m using Phonegap1.4.1

I believe your event listeners are not being established because you are using Object.bind() on the handler functions, and .bind() is not available in the iOS WebKit widget. (This is surpising because .bind() is available in the desktop WebKit (Chrome and Safari) versions.)
The easy solution is to add a polyfill definition for Object.bind(). I use the one from the MDN bind documentation page, and haven't had any problems with it.

sorry but i cant make a comment yet ;)
have you checked the two other events (active and resign only for ios)? more information: http://shazronatadobe.wordpress.com/2012/03/14/apache-cordova-lifecycle-events-in-ios-4-versus-ios-5/
or see iOS Quirks in the documentation: http://docs.phonegap.com/en/1.6.1/cordova_events_events.md.html#pause

You need to add your listeners in the deviceready instead of in the onLoad.
Just like here for example
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady() {
document.addEventListener("pause", onPause, false);
}
function onPause() {
}
Hope it helps :)

Related

How to close mobile app programmatically using IONIC 5?

How to close the mobile app programmatically using IONIC 5? Use case: Upon app start, I am displaying a Terms of Use popover and if the user does not accept, I need to close the app. I am using IONIC5+Angular.
Thank you.
V
I figured it out.
While navigator['app'].exitApp() works for Android, it does not work for iOS. Also, according to Apple, the apps should not terminate themselves. For my app, I will just display the "Accept" but. The user will need to close the app manually if they don't want to agree to the Terms of Use.
navigator['app'].exitApp();
**that's work for me **
you also use
#capacitor/app
App.exitApp();
Force exit the app. This should only be used in conjunction with the backButton handler for Android to exit the app when navigation is complete.
Ionic handles this itself so you shouldn’t need to call this if using Ionic.
HTML :-
<ion-button color="danger" (click)="close()" fill="clear" expand="block">Close App </ion-button>
TS :-
import { Platform } from '#ionic/angular';
constructor(private platform: Platform) { }
close(){
this.platform.backButton.subscribe( () => {
navigator['app'].exitApp();
})
}

GWT - Fullscreen

Is there a way to start a gwt-app in fullscreen mode (without toolbar, navigation)?
I found only a hint to open a new window:
Window.open("SOMEURL","SOMETITLE",
"fullscreen=yes,hotkeys=no,scrollbars=no,location=no,menubar=no,status=no,
toolbar=no,resizable=no");
Is this the only way?
If yes, what's the best way to use the "Window.open" (Example)?
This works for me:
private native void requestFullscreen() /*-{
var element = $doc.documentElement;
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}-*/;
This isn't really a GWT question - this is a browser-provided API that GWT happens to wrap for you.
It's worth noting that modern browsers have a tendency to ignore some or all of these flags. For example, good luck getting Chrome to hide its address bar. The reason for this is that if they honoured all of the flags, you could write a web app which looked exactly like a desktop app and the user wouldn't know it - which is exactly what you sound like you're trying to do!
or use https://github.com/wokier/gwt-fullscreen
Caffeinate response has been used as a basis. I also added an event to be notified of fullscreen state change.

PhoneGap Events Not Firing On iPhone

I've started developing for iPhone using PhoneGap and an iPhone running iOS 5. With the following code, the deviceready and online events appear to fire when the application starts but none of the others, in particular, the resume / pause events appear to. I've tried using the menu button to close the app and then re-open it but nothing appears to fire the resume event.
If anyone could shed any light on this it would be much appreciated.
Thanks in advance!
window.addEventListener('load', function () {
document.addEventListener('deviceready', onDeviceReady, false);
}, false);
function onDeviceReady() {
document.addEventListener('resume', onResume, false);
document.addEventListener('pause', onPause, false);
document.addEventListener('online', onOnline, false);
document.addEventListener('offline', onOffline, false);
}
function onResume() {
alert('resume');
}
function onPause() {
alert('pause');
}
function onOnline() {
alert('online');
}
function onOffline() {
alert('offline');
}
For me this was an ID10-T error: my PhoneGap app was redirecting to a URL which I had changed in one place but not in the other. The result was it looked like I was running my development code but I was actually running against a remote server running code without onResume and onPause events!
BTW, documentation for these events can be found at http://docs.phonegap.com/en/1.4.1/phonegap_events_events.md.html

Native HTML5 Drag and Drop in Mobile Safari (iPad, iPod, iPhone)?

I've successfully implemented native HTML5 Drag and Drop for moving HTML elements inside a page (just, say, a div from one place to another, nothing related to interacting with the host OS' files whatsoever). This works fine in Chrome and Safari on a PC but I can't start a drag operation in my iPad's Safari.
I've found this so far:
Using Drag and Drop From JavaScript
Safari, Dashboard, and WebKit-based
applications include support for
customizing the behavior of drag and
drop operations within your HTML
pages.
Note: This technology is supported
only on desktop versions of Safari.
For iPhone OS, use DOM Touch,
described in Handling Events (part of
Safari Web Content Guide) and Safari
DOM Additions Reference.
Here. But it's outdated (2009-06-08).
Doe's anyone know if it is possible to use native HTML5 in Mobile Safari? (I don't want javascript-framework like solutions like jQuery UI).
Thanks!
I've just been trying to get native drag&drop working in ios safari (ipad pro with 14.0.1), and I'm updating this answer as it kept coming up as my first google result (and no other q&a seems to be up to date).
Following https://developer.apple.com/library/archive/documentation/AppleApplications/Conceptual/SafariJSProgTopics/DragAndDrop.html
I have found native html5 drag&drop now works in safari, with a few specific notes;
You MUST set some data in OnDragStart's event; (the effect settings seem to be optional) Event.dataTransfer.setData('text/plain', 'hello');
you MUST Event.preventDefault(); in OnDrop otherwise safari will load the data you added (unless that's your intention)
OnDragOver event handler needs Event.preventDefault(); otherwise drop fails (unless intended, as docuemnted)
On ios safari, if you set OnDragStart's Event.dataTransfer.dropEffect='copy' and in OnDragOver's Event.dataTransfer.dropEffect='link' the drop fails (no OnDrop()); Seems to be the only combination that fails
I thought you required
CSS -webkit-user-drag: Element; and `-webkit-user-drop: element;
or if you prefer
Element.style.setProperty('webkitUserDrag','element');
Element.style.setProperty('webkitUserDrop','element');
but it seems just the usual draggable attribute is enough
Element.setAttribute('draggable',true);
This seems to be the bare minimum to drag & drop an element
Element.setAttribute('draggable',true);
function OnDragOver(Event)
{
Element.setAttribute('DragOver',true);
Event.stopPropagation(); // let child accept and don't pass up to parent element
Event.preventDefault(); // ios to accept drop
Event.dataTransfer.dropEffect = 'copy';// move has no icon? adding copy shows +
}
function OnDragLeave(Event)
{
Element.removeAttribute('DragOver');
}
function OnDrop(Event)
{
Element.removeAttribute('DragOver');
Event.preventDefault(); // dont let page attempt to load our data
Event.stopPropagation();
}
function OnDragStart(Event)
{
Event.stopPropagation(); // let child take the drag
Event.dataTransfer.dropEffect = 'move';
Event.dataTransfer.setData('text/plain', 'hello');
}
Element.addEventListener('dragstart',OnDragStart);
Element.addEventListener('drop',OnDrop);
Element.addEventListener('dragover',OnDragOver);
Element.addEventListener('dragleave',OnDragLeave);
Touch events do work now on Safari too (including Mobile). This article has nice code snippets that you can start from:
http://www.html5rocks.com/en/mobile/touch/

How to Bind Load event for Image in jQueryMobile

I have a mobile website running jQuery Mobile 1.0a2 and I'm currently testing in Mobile Safari for Firmware 4.1 via the iPhone Simulator.
I cannot seem to bind to the load event for an image.
I have a simple gallery of thumbnails and a large image. When you click on a thumbnail it changes the src attribute of the main img
The js for that uses the live('click' method to bind and it works just fine.
$('.gallery-navigation img').live('click',function() {
// change source of main image to new
$.mobile.pageLoading(); // show jquerymobile loading message
});
My problem is that I need feedback on this click, so I wanted to show a loading message (provided by jquerymobile) and then hide it once the image loads.
Where #gallery_image_large is the actual <img> where the src is changing, I tried the following:
$("#gallery_image_large").bind("load", function () {
$.mobile.pageLoading(true); // hide jquerymobile loading message
});
This works in Safari on my desktop but does not in the iPhone Simulator mentioned above.
For reference:
jQuery Mobile Loading Message Methods
UPDATE: I am experimenting with JQuery Image load fails on MobiOne iPhone simulator, which explains how to implement the .load manually by "checking .complete".
I changed the structure of my jquery and it's seemed to have fixed it!
$('#gallery_image_large').one('load',function() {
try { // a grade
$.mobile.pageLoading(true);
} catch(err) { // low grade
}
}).attr('src',full_src);
(as you can see, I opt'd for a try { .. } catch { .. } to verify jquerymobile is available.
Although I didn't use the solution (directly) from JQuery Image load fails on MobiOne iPhone simulator, the manual firing of load via .complete is probably a good solution for anyone else out there!