How to create background location service in Appcelerator Titanium working after restarting device - titanium

I want to make an application which will send information to a server about user's location every 30min. It is needed to provide location specific push notifications.
I need such functionality for Android/iOS, which would work in background (also if device is restarted). I found some articles covering background services and I created background service doing that, but after phone is restarted it won't work.
Is it possible with Android and iOS? How can I achieve that?

With iOS, no. With Android, yes.
Apple has gone to great lengths to limit what apps can do. You can do some things in the background for an extended period of time (GPS, play audio, Voip, etc), but after a reboot your app will not be restarted until the user opens it again. There are exceptions to this. Voip apps are allowed to restart after a reboot, but apple will not approve your app for the App Store unless you actually have a place for a user in your app to use the Voip feature. Geofences are a possibility, but I haven't had experience with that feature yet. In my experience, Apple does whatever they can to make sure your app doesn't run forever.
With android, there is more flexibility and what you propose is totally possible. I've listed some important links below, since most of those solutions are far better documented than what I can do here.
Essentially you need to register as a boot receiver and then send an intent to start a titanium android service when the boot event is received. I don't have experience with starting a titanium service, but I'm sure its a simple intent you need to fire. Either way you'll need a module for this native code. I attached a link to a bencoding titanium module that may help you, although there may be some others out there. You may even need to code one yourself.
Samsung is notorious for stopping your app with their SPCM feature. You may want to familiarize yourself with it. I've added a stackoverflow discussion link below.
I don't know all of your system requirements but honestly, for any app I would try my best to not run forever. It will hurt the battery life for your users and will add a lot of complexity. Maybe you could simply have the app check the GPS coordinates when it receives a push notification and decide right there and then whether to present a notification to the user? Just something to consider.
Either way good luck!
How to start an Application on startup?
http://docs.appcelerator.com/platform/latest/#!/guide/Android_Services
https://github.com/benbahrenburg/benCoding.Android.Tools
Dealing with Samsung SPCM killer

Related

What is the fastest and the best way to push notifications to client?

I am making app that need to supply user the latest updates as soon as possible.
My current experience is that WebPush notifications show up too late or latency varies too much from device to device (aggressive battery saving policies etc.), plus they are not supported by Apple products and I can not use WebSockets since users will probably go away and chrome will go into sleep mode, which WebPush and ServiceWorkers should solve but, as I mentioned, they have a problem.
I'm thinking that using 3rd party software or making native app (via React Native) may solve some of these issues but I'm not sure.
What do you guys think about above-mentioned possible solutions or do you guys have any solutions or suggestions?
I've tried using WebPush (latency issues) and WebSockets (user automatically disconnecting after some time)

WinRT live tile on system startup

I have a live tile working which updates how many users are online and how many lobbies are open within the app. This begins updating when my app loses its visibility (no point it updating the live tile whilst the app is running), but I want it to update when I first turn the computer on.
I have had a look around and mentions of making the app a lock screen app have popped up but that is all, no explanation how to do it.
Does anyone know how to do this and provide a nice little explanation or link of how to do so?
Many thanks,
Kevin
You should use push notifications for this kind of behaviour. This msdn link has more info:-
Using tile notifications
Choosing the right notification method to update your tile
There are several mechanisms which can be used to update a live tile:
Local API calls
One-time scheduled notifications, using local content
Push notifications, sent from a cloud server
Periodic notifications, which pull information from a cloud server at a fixed time interval
The choice of which mechanism to use largely depends on the content you want to show and how frequently that content should be updated. The majority of apps will probably use a local API call to update the tile when the app is launched or the state changes within the app. This makes sure that the tile is up-to-date when it launches and exits. The choice of using local, push, scheduled, or polling notifications, alone or in some combination, completely depends upon the app. For example, a game can use local API calls to update the tile when a new high score is reached by the player. At the same time, that same game app could use push notifications to send that same user new high scores achieved by their friends.
You're right with the assumption that you require a lock screen capability to be able to run background tasks without your app being started once. The main process would be to extract the part of your application that gets the data into a background task that is probably triggered by a timer and write some code to be on the lock screen.
When I first encountered that restriction I was kind of surprised, but in terms of battery performance this design decision makes sense: Only consume battery power if the data is absolutely worth it. If it's worth, it is also of interest having it on the lock screen.
On MSDN is a good overview about lock screen along with further reading links. It's much better than what I could type in here. Come back with problems related the implementation (which actually even better fits the purpose of SO). This blog might be useful, too.

Perform a task every day even if running only in background

I need my application to perform a background task every day, but it does not comply with Apple's specification for running in background.
It's none of these: audio, location, VOIP, news stand, external-accessory—, Bluetooth-central.
I'm planning to use local notifications, but the point is, that if the user doesn't open the app (and just leaves it in the background), I cannot plan new local notifications.
What should I do in this situation?
Make something else.
Seriously, if your app doesn’t at least technically fit one of those categories, you’re not going to be able to get it to do background work in a way that’ll get you approved for the App Store.
I’ve seen apps that added specific functionality in one of those categories, orthogonal to their actual purpose, to be allowed to run in the background; for instance, there’s a couple of weather apps out there that play a continuous audio file—one of the available sounds being a silent one—in order to be able to update the lock screen’s “now playing” image with live data. If you don’t mind your users being unable to listen to any other music, and have your app continuously active (which might cause additional battery drain), that could work. But if you’re trying to have your app invisibly do things in the background, without interfering with anything else, in a way that’ll get you into the App Store, you’re probably out of luck.
Four options:
Go for jailbreak
Try to get in the app store as one of those types of apps, making up a feature that uses one of those types.
(my favorite) Really rethink your system, is it really necessary to schedule background tasks? Can't the user wait a bit when he opens the app? That loading can be performed in background. And can't you offload some of the work to a webserver? Are you collecting data? You shoudln't without the user consent.
Let your user know that it's important for him (he's the one using it right?) that he opens the app once a day.
I think I covered all yohr options except the one already covered by Noah.

Turn iPhone into a server programmatically?

I want to make my iPhone app display on a Mac's screen, kind of like AirPlay does with other machines. The only way I have heard to do this is, although I do not like it, turn the iPhone into a server. Unfortunately, I cannot figure out how to do so. I also wanted to set it up in such a way that my Mac automatically detects it. I have seen a similar setup in the game Chopper 2. My Mac app will have a simple timer that fires every few seconds to look for the iPhone, in the same way that Chopper 2's "Find iPhone" button does.
Is there a simple way to turn the iPhone into a server, or start a "session" like Game Center does?
One last thing: I know it is somehow possible, because another app I have actually gives my iPhone a web address at the click of a button. It is called the Dicenomicon, if you want proof.
First there is no easy way to redirect your display to Mac, even if you made it a server of some kind.
Second, to discover or publish customized services on WLAN, you may want to refer to the samples on Bonjour:
CocoaHTTPServer: a simple TCP/HTTP server.
WiTap: an app that discovers and connects to services of the same kind on WLAN by Bonjour.
I'm not really sure what you mean by "server", because there is no way to share the screen of an iPhone using the official SDK, although this is possible by jailbreaking.
It would be possible, however, to send data back and forth between the Mac and iPhone, and display the data on the iPhone, on a Mac. Using that data, you could try to recreate the interface on the Mac. All of this could be accomplished using sockets. A class that might help with that would be cocoaAsyncSocket, which makes network programming a lot easier.
The auto-discovery of iPhones on the local network is achievable with Bonjour. Without getting into too many details, NSNetService would allow you to publish a service for your app from an iPhone, and NSNetServiceBrowser would allow you to find that service on the local network from the Mac. From the NSNetServiceBrowser, you could establish a socket connection with the iPhone.
Good luck!
You might want to take a look at the GameKit APIs, I know they do something similar between two iOS devices.
http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/Introduction/Introduction.html

task with action in background service

I've been searching an googleing over one hour now and I'm not really sure of it's legal and possible to add some tasks in an background service that triggers an action ( and bring the app to the foreground ).
With tasks i mean that the background service is doing something on an indicated time. I know its possible to bring up the IOS alert with the notifications ect... But an simple notifiction is not good enough.
Actually I wanna play an video, and if this is not possible maybe the audio ? Since bringing the app to the foreground is not possible, or is it?
What are the options?
It's not acceptable to take away the user from what they are doing, this applies to iOS since it's a one-thing at a time OS. How would you feel if an application switched to itself while you're playing, chatting or half-way reading an article?
Apple doesn't allow it, you should stick to the Notifications, and if the user truly wants to see/hear the video/audio, then he will go to your app.