Ok here is my problem, I've inherited an old ASP.NET 2 website which I've been asked to make iOS capable. My biggest headache so far is that because of the way you have to log into the system right now I need to pass the UserName to the iphone and also run the server Click event. I can do one or the other but not both, and hooking up to the username textbox via either the KeyUp event or the OnChanged event causes other problems with the Objective-C code for the iPhone.
Is there anyway that I can update both the phone and the server at basically the same time?
Related
I am developing a Windows 10 UWP App in javascript.
One of the requirement is to show a notification but only when the app is in background, not foreground.
My question is, what is the best way to check if the app is running in background/foreground, using javascript. Many thanks.
You use the same APIs you use from a Web page: Use document.hasFocus() to determine whether the app has focus. You will also receive the window.blur and window.focus events when you lose and regain focus.
what is the best way to check if the app is running in background/foreground, using javascript.
If you check the app lifecycle, you could use WebUIApplication.EnteredBackground Event and WebUIApplication.LeavingBackground Event to do judgement. For example, you could use ApplicationData.LocalSettings to store the states of current app. When the EnteredBackground or LeavingBackground event is fired, you could change this localsettings value in its event handler. Then, when you want to detect the app's states, you could get this localsettings value and do judgement.
Please note that this question is in consequence of another question: "Codename One - ToastBar when “No connectivity detected"
What is a correct approach (in Javascript or JQuery) to deal with Internet connection unavailability (that is common on mobile devices)?
Every time that there is a networking error, I would like to show a message to the user (like this one: https://i.stack.imgur.com/Ll6jD.png) and pause the Internet activity of the web page, in a way that no errors are generated (and the messages written by the user, for example in an html form, are not lost). The Internet activity should be (automatically) restored when the connection will be available again.
This should be a convenient way to allow people to interact with a web site (from mobile devices) without the risk of losing their posts or comments and without receive errors when they click a link.
This functionality should be as much as possible independent from the specific web site. What is a correct way to implement it?
use jquery plugin like this :
Offline.js
My PhoneGap application need to emit a websocket (to update the connection status) message to the server when the "pause" event is captured.
Android
With Android device there is no problem by using this piece of code :
document.addEventListener("deviceready",function(){
document.addEventListener("pause", function() {
socket.emit('changeStatus', 'incative');
});
document.addEventListener("resume", function() {
socket.emit('changeStatus', 'active');
});
}, false);
iOs
In iOs this is a different kettle of fish. Indeed here is the official PhoneGap documentation about the "pause" event :
iOS Quirks
In the pause handler, any calls that go through Objective-C will not work, nor will any calls that are interactive, like alerts. This means that you cannot call console.log (and its variants), or any calls from Plugins or the PhoneGap API. These will only be processed when the app resumes (processed on the next run-loop).
When they say "calls that go through Objective-C will not work", are they talking about using network access ?
Indeed when I test my app on iOs my "changeStatus" message with the value "inactive" is send when I resume my application.
Here is my second question : Is it possible in phonegap iOs app to access the server after capture a "pause" event ?
Thanks for your help
I dont think it's possible because of several security issues on iOS.
As alternative solution, you can run an echo function at socket server end, which will continuously emit message to that particular user at a particular intervals. If user responds to that message, you can consider that user as a active user else consider him as inactive user.
It's also not a good practice for user to send his activity status. Consider what will happen if user lost his connectivity? You will never come to know if he is active orsleeping..
Hence its better to check it by ping at server end..
I am trying to bind a call to 'backbutton' event that is supposed to be called when a cordova app is run on an android device and the user hits the back button.
http://cordova.apache.org/docs/en/3.0.0/cordova_events_events.md.html#backbutton
I cannot seem to get this event to fire.
This google groups post references that the App plugin has been removed and doesn't seem to provide any solution, just wait for cordova 3.1.
https://groups.google.com/forum/#!topic/phonegap/qgo-HdW4C_g
According to the post in google groups the device api has not included in js file. So you need to wait for the next release.
This link may help you to use customize plugin to handle back button in android.
Send Application to background mode when back button is pressed in Phonegap
I am working on a multiplayer chess game as a Facebook app.
If one player leaves the game by closing the browser the other player should get a notification. So if one player closes the Browser, a unlink function should be called to unlink the player. This works fine with onunload outside Facebook.
The problem is, that the Facebook apps are loaded in iframes and the onunload event doesn't work there.
So I need a way to call a function inside an iframe when a user is closing the browser.
This is probably not the answer you are looking for but "logging off" on unload will never work reliably. For an extreme example, consider the case where the browser crashes or is killed via the Windows task manager. So you better implement an additional mechanism to detect whether a user left. Typically this is done by sending a request to the server periodically. If this request isn't received for a significant time (meaning something that cannot be caused by a slow connection or other hiccups) you unlink the user.
That said, I tested Firefox 4 and MSIE 8 and both correctly fire unload event on the frame if the tab or the browser is closed. Chrome 12 doesn't do that, that's probably the browser you have been testing with. I consider it a Chrome bug.