Is there a way to keep screen awake in a progressive-web-app? - progressive-web-apps

I plan to make a progressive web app to display the time remaining in a meeting. I need this to keep the display always on. Is there any way for a progressive web app to avoid screen to go to sleep and blank ?

Update July 2020:
Chrome 84 now ships with the Wake Lock API https://www.chromestatus.com/feature/4636879949398016 which can be used to prevent the screen from turning off.
You could use the Standby API however support is still limited.
Then there are hacks such as playing a video infinitely or the nosleep script, however from my experience they don't work consistently either.

Here's the documentation for the Wake Lock option in Chrome:
https://developer.chrome.com/articles/wake-lock/
Note that it's only available on HTTPS. (Normally not an issue, although some non-public internal applications can be standard HTTP.)

Related

How can I code an efficient mobile site like gmail's?

My web site has a different mobile version that's suited for iPhone/Android devices. The problem, however, seems to be in the site's performance. It's really slow and heavy, even though I'm not loading any images.
On the other hand, when I use Gmail's or YouTube's mobile version, they're so fast they almost perform like a native mobile application.
How do they do that?
Your help is much appreciated :)
See my comment. Also, if the slowness you perceive is when interacting with the site it could be that it lacks the ability to accept touch events. On mobile web, if you have not wired up the UI for js touch events the experience will seem slower because the device browser has to fall back to standard click and other mouseevents which are not optimal. Frameworks such as mootools and jquerymobile/jqtouch have these events baked in. Take a look at the mootools solution which has quite a good write up: http://davidwalsh.name/mootools-touch
They probably making use of local storage http://dev.w3.org/html5/webstorage/
Are your pages too large? Try to use gzip and/or reduce output
Your server's connection speed may also be responsible of slowness
Well, You don't need to include any javascript framework to make it fast clickable.
By implementing some JavaScript you can achieve that. Google has released a solution for that
https://developers.google.com/mobile/articles/fast_buttons
This will allow visitor to interact with application native way. From Android 4 (as far as I remember) version by setting viewport meta tag the browser will automatically apply the fast click functionality.
For the animation issue always use Hardware accelerated animation with a fall back for older mobile browser. Using hardware accelerated animation it will make your application smooth as silk.
Follow this guideline and you can make your application as fast as gmail / youtube mobile version.
http://www.html5rocks.com/en/tutorials/speed/html5/
Best of luck.
Your webapp is consuming too much RAM. Don't use so many libraries and don't attach so many event handlers.

iPhone sdk, Running app in background and send frequent http request

I am trying to take advantage of iPhone 4 multitasking feature. I want to run app in background and frequently send http request to send/receive data, is it possible?
Surprisingly, there is actually very little time-slicing going on in the "multi-tasking" iOS 4.x. What goes on instead is really just application suspend / resume. When an application is sent to the background upon the user tapping the home button, it will stop getting execute cycles after a short while (*).
(*) There are a few exceptions. Applications which declare themselves as "VoIP providers", location-based apps, and music apps can get background execute cycles, presumably only though to perform those very specific operations in response to corresponding events (like a "significant change in location" occurring). Some apps apparently try to stretch the rules and find undocumented or not-strongly-documented techniques to continue getting background execute cycles.
And the "requested running time" that Undeadlegion mentioned is limited in duration.
The reality is that on iOS4, applications are not allowed to run continuously in the background.
#Undeadlegion has suggested a plausible way to achieve your goal. To be more clear, take a look at my previous answer to a similar question at SO, iphone - Connecting to server in background
It is possible to request running time while your app is backgrounded.
See Multitasking Developer's Guide
Although, depending on the intent of your http requests, push notifications may be a viable alternative.
This may be necessary because you aren't providing audio, voip, or location services, so your app can't run in the background indefinitely.

is there any API to forbid user capture app screen as image? [duplicate]

I'm working on an enterprise iPhone application for a client, the issue at hand is customer information will show up on the phone. My client is worried that the information could be caught using the iphone screen capture feature (home + power button), then emailed or synced from the phone. Is there any way to disable the screen capture feature? Can this be done programatically or is is possible through a configuration profile?
if your customer could retain the ownership of a handset, they can restrict Screen Capture feature using iPhone Configuration Utility. Make sure you don't give these phones to any one outside of this organization, otherwise you are in violation of your Enterprise legal agreement with Apple.
Since this is for an enterprise app, perhaps you could put a transparent overlay view atop everything, that in a drawRect went opaque when it detected the layer was being asked to render for a screen shot (perhaps by looking back up the stack trace?)
You might try setting debug points in every possible view and layer drawing methods, and see if anything is triggered by a screenshot.
Screen capture can be enabled/disabled for iPads/iPhones that are managed via the iPhone OS Configuration Utility. See page 33 at http://manuals.info.apple.com/en_US/Enterprise_Deployment_Guide.pdf where it says:
** Allow screen capture: When this option is turned off, users are unable to save a
screenshot of the display.*
In other words, in enterprise deployments where the "customer" owns the iPads (or requires employee-owned devices to be configured by IT) screen capture can be suppressed at a device level.
It's also possible to detect if screen capture has happened and to record this (so perhaps a manager can pay a friendly visit).
It is not possible to suppress screen capture under program control. Apple prefers to exercise tight control and grudgingly yields a bit to enterprises. It doesn't yield much to developers. (How do you like being a sharecropper on Apple's plantations?)
Seriously, there are good reasons to control screen capture. In the education space, we'd like to use iPads as secure testing devices. In a proctored test environment, the proctor can make sure a student doesn't have a camera or notepapers to carry away test questions. Therefore the major remaining risk to test item security is the screen capture. If you couldn't suppress it, students could quickly snap every test question they encounter and email them to their buddies (or post them online or sell them to a test-prep company).
For random consumer iPads used under uncontrolled conditions, developers don't have this capability. Them's the breaks :-).
No, there isn't. The user is always able to perform this function.
Yes, you can do this in at least two ways. Internet Testing Systems (ITS) of Baltimore has an iPad testing app in the store, interestingly it is "PEARSON NNAT2 -Stanford 10 - OLSATS", a Pearson app that can be used to take any of these three tests. see https://itunes.apple.com/us/app/pearson-nnat2-stanford10-olsat8/id546817211?mt=8 -- it is free and you can download it.
If you simply require your user to put the device into Guided Access mode after starting the app and before proceeding, using UIAccessibilityIsGuidedAccessEnabled(), you can then prevent the user from using "print screen" -- OR from switching to any other task. Examsoft is a vendor that uses this approach.
These features are generally of concern to test publishers and assessment delivery vendors; I have a blog post and screen shots the ITS approach, and code to emulate the Examsoft approach, here: http://mindstormtools.com/2013/02/23/ipads-for-assessment-test-delivery-profile/ and http://mindstormtools.com/2013/02/20/ipads-for-assessment-guided-access/

Does iOS 4 make “Real Multitasking” available to 3rd party developers?

Ever since the first beta came out I’ve been trying to find out if “real” multitasking is possible — i.e. can you put a program in the background and have it hang on to a network connection indefinitely?
I’m thinking about IM or IRC apps, for example. I’ve compiled an app myself on iOS 4, and without changing a thing it appeared to stay running in the background, but for all I know it was just suspended to memory.
The docs say the best you can do is request up to 10 minutes, but in the developer presentation they showed off Skype sitting in the background and then notifying the user that a call was coming in. Does anyone know for sure how this all works?
It appears the answer is no. The API for Skype is a very special case, called the "voip" mode, and requires special behavior, such as marking the socket in use for VoIP.
You can receive alarm notifications in the background (such as time passed). The amount of time you are in the background running state is severely limited by the OS.
Android's background model is complete and in many ways much nicer.
Apple has a guide named "Supporting Multitasking In Your Applications" which you should be able to locate.
Apple's iOS 4 developer docs outline this all very clearly.
When your app is closed or switched away from, it is almost immediately "suspended", meaning the OS freezes the app's state. When the user switches back to your app, your code keeps running just where it kept off. You don't need to add any code to your app to do this, just compile it against OS 4.
The above is true in most cases. There are two reasons the "suspended" model may not apply:
1) If the device starts to run low on memory, the OS will start terminating suspended apps that haven't been switched to in a while, without warning. This is why it's in your best interest for your app to remember it's state as well, so if your app is terminated, then re-opened, the user doesn't really notice because it still returns to right where they left off.
2) Your app uses one of the "background" APIs. These are for audio playback, VoIP services, or location services. In this case, your app is allowed to continue running in the background but only has access to those APIs. Additionally, your app can designate certain long-running tasks as "background tasks" that need to be completed before the app is suspended or terminated, like uploading pictures to Flickr or rendering a video, etc.
The "background task" method doesn't cover pinging servers indefinitely, as there is a time limit for the task, after which it will be forcibly halted. Apps that need that sort of functionality are expected to implement push notifications, just as before.
That should clear this up. All in all I think it's a pretty elegant solution to multitasking on a mobile device.
iOS 4 applications can either be running or suspended. The operating system will try to keep as many requested applications as possible in memory, while all other applications are suspended.
Applications that run in the background can access features such as navigation, audio, and VOIP (but NOT instant messaging). So it looks like you might be out of luck.
-- PC World Multitasking on Apples iPhone 4
It is possible for apps to request background time. Read the docs. I would say it iOS is "controlled multitasking".
You can create a long running background task, I believe these can include networking features. Just have to set the background task flag on the work block.
https://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
the OS can limit exactly how much time you get though... it will tell you when your time is up giving you a chance to cleanup nicely.
iOS 4 has "real" multitasking to some extend. There are two things to consider:
The UI event loop is single tasking. So only the front app executes on the UI event loop. Not a big deal: detach your main code form the UI event loop (maybe you need to redesign your app).
The OS "may" terminate your app if some criteria are met (e.g. low memory).
Currently one of these criteria is that execution time is limited to 10 minutes (real time not cpu time). However I expect this to change and see better criteria for background app termination (I hope to).
Apart from this you can have timers (event loops) in background.
There is no real multitasking in iOS 4.2 even. because apps will only be allowed to finish the task related to states..for small interval of time and then it will be in suspended state.. If you will set background task for long interval of time then... it will behave unexpectedly like no method will be called when you will try to run the app from anywhere..
You may be interested in this blog post that outlines how "multitasking" works in systems such as iPhone OS 4 and Android.
in fact u can do this, although it's not allowed by Apple. u gotta set up a toolchain in ur mac and use some unofficial SDK...
check http://code.google.com/p/iphone-backgrounder/ for more information
You should use the Push Notifications framework for the feature set you are creating!

Disabling iPhone screenshot feature

I'm working on an enterprise iPhone application for a client, the issue at hand is customer information will show up on the phone. My client is worried that the information could be caught using the iphone screen capture feature (home + power button), then emailed or synced from the phone. Is there any way to disable the screen capture feature? Can this be done programatically or is is possible through a configuration profile?
if your customer could retain the ownership of a handset, they can restrict Screen Capture feature using iPhone Configuration Utility. Make sure you don't give these phones to any one outside of this organization, otherwise you are in violation of your Enterprise legal agreement with Apple.
Since this is for an enterprise app, perhaps you could put a transparent overlay view atop everything, that in a drawRect went opaque when it detected the layer was being asked to render for a screen shot (perhaps by looking back up the stack trace?)
You might try setting debug points in every possible view and layer drawing methods, and see if anything is triggered by a screenshot.
Screen capture can be enabled/disabled for iPads/iPhones that are managed via the iPhone OS Configuration Utility. See page 33 at http://manuals.info.apple.com/en_US/Enterprise_Deployment_Guide.pdf where it says:
** Allow screen capture: When this option is turned off, users are unable to save a
screenshot of the display.*
In other words, in enterprise deployments where the "customer" owns the iPads (or requires employee-owned devices to be configured by IT) screen capture can be suppressed at a device level.
It's also possible to detect if screen capture has happened and to record this (so perhaps a manager can pay a friendly visit).
It is not possible to suppress screen capture under program control. Apple prefers to exercise tight control and grudgingly yields a bit to enterprises. It doesn't yield much to developers. (How do you like being a sharecropper on Apple's plantations?)
Seriously, there are good reasons to control screen capture. In the education space, we'd like to use iPads as secure testing devices. In a proctored test environment, the proctor can make sure a student doesn't have a camera or notepapers to carry away test questions. Therefore the major remaining risk to test item security is the screen capture. If you couldn't suppress it, students could quickly snap every test question they encounter and email them to their buddies (or post them online or sell them to a test-prep company).
For random consumer iPads used under uncontrolled conditions, developers don't have this capability. Them's the breaks :-).
No, there isn't. The user is always able to perform this function.
Yes, you can do this in at least two ways. Internet Testing Systems (ITS) of Baltimore has an iPad testing app in the store, interestingly it is "PEARSON NNAT2 -Stanford 10 - OLSATS", a Pearson app that can be used to take any of these three tests. see https://itunes.apple.com/us/app/pearson-nnat2-stanford10-olsat8/id546817211?mt=8 -- it is free and you can download it.
If you simply require your user to put the device into Guided Access mode after starting the app and before proceeding, using UIAccessibilityIsGuidedAccessEnabled(), you can then prevent the user from using "print screen" -- OR from switching to any other task. Examsoft is a vendor that uses this approach.
These features are generally of concern to test publishers and assessment delivery vendors; I have a blog post and screen shots the ITS approach, and code to emulate the Examsoft approach, here: http://mindstormtools.com/2013/02/23/ipads-for-assessment-test-delivery-profile/ and http://mindstormtools.com/2013/02/20/ipads-for-assessment-guided-access/