Detecting inactivity in fennec - firefox mobile extension - firefox-addon

I'm building an addon for firefox mobile (fennec).
Is it possible to detect if the browser is running in background or the screen is locked so that I can suspend some task that is running within my extension?

You can also listen for the "application-foreground" and "application-background" notifications. Firefox does this itself here:
http://mxr.mozilla.org/mozilla-central/source/mobile/android/chrome/content/browser.js#5445

I don't think that you can - Fennec itself doesn't seem to care whether the screen is on or off, at least I couldn't find any code checking that. Normally I would recommend js-ctypes to call the necessary OS functionality directly but it is of very limited use on Android. So I guess that the best thing you can do is using nsIIdleService to detect when the user has been inactive for a while.

Related

Appropriate background mode for Swift NIO client

I've created an iOS app, that connects to an embedded device using swift-nio-ssh. This app has no UI to control the device, as that is supposed to be done with a Watch app, using WatchConnectivity.
As it stands, I have to keep the iOS app in the foreground or the SSH client will die after a few seconds. Instead I'd like to be able to keep the proxy app running in background, screen locked or whatever else the user wants to do with their iPhone.
I've done research on background modes, but none of the available APIs seem to fit my use case.
Have I overlooked something?
If not, would I be able to abuse another API instead (Audio, VoIP or NetworkExtension from what I've gathered)?
If so, would the app still be able to pass the review process somehow?
Thanks!
You haven't overlooked something and this applies to everything, not just SwiftNIO-using apps. On iOS, if an app goes into the background then it will be stopped and network connections will die at some point.
The only way around that are the mainly VoIP exceptions you mention in (2) which you have to specifically request from Apple.

ios 8 periodic background process even after app termination

NOTE: This app I am working on is completely for my own usage and will not be on app store so please don't give answers referring that.
I want my app to do some process in background or after termination (double tap the home button and swipe the app from applications multitask) every few minutes. The process is very very light and quick so it won't drain the battery. This process shouldn't require internet connection. I have seen some answers here like and I will explain what are the problems:
VoIP. The problem with VoIP is wither it should be in background to use UIApplication.sharedApplication().setKeepAliveTimeout(..) method which doesn't work when the app is terminated or it should be connected to the internet to establish tcp connection and receive commands from sever and as mentioned before I want it to be internet independent.
Location Services. I found this excellent site with some great articles but the problem is it only works when the mobile phone is moved more than 500 meters. It depends on the location movement so when the phone is staying somewhere there will be no code execution.
Playing an silent audio loop. The problem here is if the user plays another audio (which is completely possible like music or phone call) the app will terminate!
Jailbreak Launch Daemons. I can't require jailbreak so it should be solved with a non-jailbreak solution:(.
I am free to use any kind of private-API's and there will be no restriction for that.
Thanks in advanced
I also faced with such problem, and don't find any solution.
The main problem is if user manually terminated app - in this case you can't do nothing...
Only way is:
a) use Location Services (as you mention)
b) use Push Notifications with background fetch

Working in background in iOS

I'm an android developer and I've started learning iOS development - not so long ago. I have
an android app which I want to port onto iOS. My app has
a background service which tracks user geoLocation and sends it to my server then receives response from it and then writes this response to SQLLite, please tell me how much it is possible to make this on iOS? I know that iPhone can receive location updates in background since iOS4, but what about background network connections and SQLLite? Also is it possible to send local push notifications in background?
please tell me how much it is possible to make this on iOS?
iOS is a mature OS that comes with Cocoa Touch, a huge library of classes. So, yes it is possible. And the question of possibility shouldn't be attached with the word much. Either something is possible, or something is impossible. Don't take it as how much. If it is possible, you can do it.
how about background network connections and SQLite?
Of course, this is possible. Like android, there is a rule in iOS that only your main thread can interact with the UI, and all other heavy tasks should be attached with other threads. You will use Blocks to accomplish this kind of functionality.
Also is it possible to send local push notifications in background?
Yes, it is quite possible. Have a look at the following document.
Local and Push Notification Programming Guide
Do have a look at http://developer.apple.com/, here you find a lot of documents related to the tasks you have asked in your question.

Create an iOS App that runs as Web Server in background

I want to make an iOS application (for iPad specifically), which behave like a web server.
I saw the examples coming with COCOAHTTPSERVER, but i didn't understand something.
Is it possible for my application, while being in background, to receive a request from another application running in the same device?
If it is possible how can i do this?
Otherwise, if it is impossible, what is the meaning of a web server application, that can't work in background?
My exact problem is as follows: I need an iOS application that can receive a request from a javascript application, running on safari, in the same device. Can i create an application behaving like a web server in background (because safari must be in foreground), or there is another way to implement this?
You can run a web server in the background on iOS but unfortunately only for a limited time (up to 10 minutes max) and the OS can stop it at any time. See this tech note [1] for more info.
If that limitation is acceptable to you, you should use an already existing web server like GCDWebServer which handles background mode for you [2].
[1] https://developer.apple.com/library/ios/technotes/tn2277/_index.html
[2] https://github.com/swisspol/GCDWebServer#gcdwebserver--background-mode-for-ios-apps
This library may make your task much easier.
https://github.com/swisspol/GCDWebServer
No, iOS does not support web servers running in the background.
The reason Apple does this is that a web server has to listen for inbound network requests. Listening for inbound network requests requires that the radios be active all the time. Active radios drain the battery.

Is there a way to prevent iOS6 to kill the specific task process?

I know that iOS has its own task management method and users may never need to care about the processes background. But my requirement is to ALWAYS keep a program alive, it cannot be killed under any circumstance.
Is there a way to do this like "LOCK" or something else function already existed? I'm using iPad4 ios6.01 system.
Thanks
No, that's not possible. (Nor should it be if you think about it. What's to stop every app from saying that it can't be killed?)
The closest you can get is for things like VoIP apps that do run in the background and automatically respawn when they die.
The alternative is to work like every other app: when your app goes into the background you save state so you can restore if it gets killed. iOS 6 even has the state restoration functions.
Short and simple
No, there is no way to make your App "unkillable".
A bit longer
If your App requires to receive location updates while it is running in background, you can use the standard way Apple offers to do so.
Two other options are: your App is an VoIP application (afaik they also get autostarted on system boot) or you're playing audio in the background. Without knowing too much details about how iOS handles such Apps, they might get killed if the iDevice runs out of memory (or the user kills it). But you probably already knew that.
However, as you already mentioned, iOS manages everything on it's own and will kill Apps that run in background to free memory. Additionally as we all know, a user might kill your App at any time using the task switcher of iOS.
And don't try to use the described methods just to run tasks in the background. If Apple finds out about it, your App will be rejected/removed from the App Store quickly.

Resources