Tracking device useage on iOS - ios

I've been using this app called Moment that tracks how much time I spend on my device every day. I think it's very cool, and at the same time am very curious how it works. I don't have tons of mobile development experience, as I've mainly built web apps, but I'm curious how this kind of functionality could be achieved.
I did a few quick Google searches and found that iOS does have some support for background task execution. The functionality lies in four categories:
Play audio
Receive location updates
Perform finite-length tasks
Background fetch
It looks like I can't do anything tricky using audio callbacks, as Apple will reject the app, but I'm wondering if I can do something with (3).

They do it using Custom Profiles.

Related

Relaying data between iOS devices with app in background

This might be asking for the moon but here goes...
Is it possible to have an iOS app receive data and then forward it all while running in the background?
We're a restaurant currently using an ordering system that uses a main iPad as the till, with a second iPad in the kitchen to receive orders, and another third iPad used by the servers to take orders. Orders are sent to the main till which relays orders to the kitchen.
Works great... Unless someone switches app on the main till iPad to our other (necessary) hosting app, then all hell breaks loose and all orders stop getting sent.
Developer (small team) has told us it's impossible to solve but I have done some digging into recent Apple APIs that allow simple tasks to run in the background and have seen a few promising options, or perhaps it's possible via the External Accessory Framework, or even syncing via iCloud? A question for the more knowledgable than me, but is there currently a workaround to solve this that I could suggest or are they right in that it's currently impossible in iOS?
Yes there are ways to have an app in the background receive data, generally using either:
beginBackgroundTaskWithName:expirationHandler:
or
beginBackgroundTaskWithExpirationHandler:
Take a look at the Background Execution section in the documentation for more info...

iOS Background task to check for server availability

This is my very first post on SO!
I'm a beginner iOS developer and I'm looking for a solution for my Swift app.
Is there any way to implement functionality to ask for a server availibilty on a regular basis (e.g. every 5 min) even when the app is not running. That would only require a simple http request so the app would work as a monitoring tool for a specific server. I tried using Background Fetch but it doesn't seem reliable enough since I can't force it to run every 5 minutes.
Is it possible to achieve that in iOS or maybe there are some better ways to implement such monitoring tool?
EDIT:
To partly answer my question I've found this solution that requires the abuse of Apple policy regarding multitasking:
http://yifan.lu/2013/12/17/unlimited-backgrounding-on-ios/
It requires the use of Audio / AirPlay Background Mode, but I can imagine that Apple won't accept such app in the AppStore. Is there any 100% proper way to achieve my goal?

How to detect data being per app basis on iOS

I recently came across an app in the app store called Dataman Pro. It has a feature that lets you see the data usage per app basis (see the attached screenshot). I have been wondering what is it doing to get this sort of information.
See this post about getting the list of installed apps, and this git project.
Then about usage tracking:
If you wondered about any public APIs that give you network statistics out of the box - there's nothing there.
DataMan it self is an app that used to work in the background all the time, and bind to the network interfaces to track network usage. Which is one of the reasons that its data is never 100% accurate as it is not guaranteed to always work in the background. This is also the reason Apple kicked it from the AppStore after a few versions...
Now that app has returned, if I understand correctly, after making a few changes: Mainly avoiding "hacks" to stay in background, and using Location Services to get back online when the user moves around. I guess this is another hack but one that Apple did not oppose to, yet.
Edit:
After looking around the web for a bit, it seems that Apple found that trick also, and removed many apps from the AppStore due to staying in the background by using location. I guess right now it's not working more than 10 minutes in the background, so you open it when you want to measure current Activity, and it stops measuring after 10 minutes.
About the tracking code itself, its mainly C code, using CFNetwork framework, and you can find some answers on stackoverflow on this subject.
More, in response to comment:
Well, the part about seeing the installed apps list, and foreground app, is not exactly private APIs, but private plist, as you mentioned.
Apps which access private files do get through from time to time. When Apple finds that some "private" files are accessed and need to be kept safer - they change it in an iOS update, like they did with the call history file, which is sensitive. Old apps tended to use (around iOS <= 3.3) the call history db to do some stats, and on iOS4 they were obsolete by the file moving to a secure location.
Reading "private" files which are unprotected is pretty easy to do without getting caught by automatic analyzers.
When you know which is the foreground app, and you can count current network usage, you can associate it with the app... And get an estimation. So this is how they do it, most likely.
However, The techniques change from time to time, due to Apple re-reviewing apps and their own policies, and due to API changes, and if you track the history of such apps and even this specific app - you will see that from time to time they get kicked off of the AppStore and return with a twist. They adjust... So no technique is reliable and this is a major headache to maintain, which is probably why the developer charges 9.99$ for it. I would.

iOS Background Mode

I have a question about running an app in the background.
I know about how to do it, but Apple does not like the way I'm doing it.
To get you on the same page, I have a security app, and I need to it monitor the device even when it is in the background. It is sort of like a burglar alarm.
I was using background audio mode, thinking it would be okay because I will be playing a sound when it is triggered. Needless to say, Apple didn't like that.
So I added a ping! It pings while active, therefor playing background audio while in the background.
Once again, they didn't like that either.
My app monitors the accelerometer as well (but not always, only when chosen by the user).
My question is, how are apps like Skype, and other similar apps able to turn the status bar red, and stay in the background? (Even some alarm apps will do this, without playing any audio or anything).
Also I can't use the notification system because it does not update fast enough if I'm monitoring the battery level. For my app I need immediate response.
I have also searched around tirelessly for this answer before I posted my question (the answers I have found, do not work for me..) :(
I would greatly appreciate any insight on this, Thanks in advance!
(If you need anymore information, please ask!)
From what I can tell from their documentation, it seems that the only way you can maintain a persistent background connection is by using one of their seven background mode keys, which I can see you've been trying since you registered for background audio. I know some alarm apps as well that use this feature (e.g. Sleep Cycle), and my assumption is that they are also using background audio mode, considering the other six modes are not remotely close to what they would need it for.
I think Apple's reasoning might be that these apps are allowed to do so, because their app is designed to be used when the user is not using the phone actively (i.e. when they're sleeping), and requires the audio to wake the user up, whereas if you are running a security app that wants to be active at all times, it may interfere with other features the user may use like Skype. The red bar will also persist at the top of the device at all times when the user is using it, which they may mistake for something that is still playing since usually when a red bar appears it means to the user that they are still actively using something. Again, I think wake-up alarm apps and others like them that aren't using persistent audio are able to get away with this since they are designed for use when the phone is inactive, so having the persistent red bar when the app is not visible is less of an issue.
In some other cases, like Nike+ (discussed here) and likely pedometers, they seem to be using the location background mode, since they often also track where you went and need to know distance. In that discussion I linked to, it looks like others were able to get accelerometer updates by registering for a background mode that applied to them. Have you tried registering for location movements? One downside I can see to that is it might drain battery life quicker, but if you check location infrequently it might not be too bad? Another is that I don't think you can directly play audio when in location background mode, but you could try to trigger a sound notification? :) That might be a nice workaround for it if that works for your app.
Again, the reasoning I have for why these apps are able to do it is just based on how I've seen other apps operating, and Apple may have different reasons for why it accepts them, but that was my best way of thinking why your app got rejected for using those modes while the others are able to do it. If location isn't what you're looking for, unfortunately I'm not sure from what it sounds like your app is doing that you'd be able to operate it continuously in the background in the way you're expecting.
Being responsive is a need for every app. Users want to have apps which have their content ready when they open it, so developers should use Background Modes to make their apps more user friendly.
Turning on the Background Modes capability
Go to Xcode and open your project.
In your app target, navigate to Capabilities tab.
Turn on Background Modes.
Background Fetch
Background fetch is a new mode that lets your app appear always up-to-date with the latest information while minimizing the impact on battery. You could download feeds within fixed time intervals with this capability.
To get started:
1- Check Background Fetch in capabilities screen in Xcode.
2- In application(_:didFinishLaunchingWithOptions:) method in AppDelegate,
Reference: https://medium.com/#javedmultani16/background-modes-in-ios-3da25b9e6474
You can use background modes only if you actively use the activity that keeps the app awake: e.g. continuously playing audio is a valid use of the audio background key. They'll look pretty hard at whether you really need the access you request, and if not they'll reject you (as you've already found out), as background services drain the battery considerably more than others.
From the docs:
These keys should be used sparingly and only by apps providing the indicated services.
Short story: I think you're out of luck with your proposed implementation.

real time messaging for multi player game on ios

Building a multi player iOS game where players compete one against the other. Nature of the game is synchronous. Basically, players either invite each other through facebook, email, etc and then start playing.
We debate what is the best strategy for facilitating the real time communication between players (sending events, etc). Coming from web development, we used comet and long polling which worked great. However, it's not clear what's the best way to achieve that on iOS.
Seems like APN (Apple Push Notifications) is not suitable in our case for two reasons: the delay can be pretty significant, up to few seconds, as far as we understand. Also, using APN requires the user to authorize notifications. If the user doesn't authorize this then it won't be possible to play the game.
Also, we understand Apple's Game Kit (Game Center) can be of value in our case however it's not clear how it interacts with invites through facebook etc. Also, not clear if we need to get into bed with Apple's Game Center and how it'll affect the user experience.
Any guidance on this matter as well as other options that you might think of would be greatly appreciated.
Thanks for your help.
Before you read the rest, a disclaimer: I work for Realtime.co but I do believe I can help here so I'm not trying to "pitch a sale".
If you need to have real time updates, you can check out Realtime (www.realtime.co). It's basically a set of tools for developers to use real time technologies on their projects. It uses websockets but does fallback to whatever the user's browser supports (such as long polling, for example) if you are using a browser (which is not your case, but it's always good to know).
Behind Realtime you have a one-to-one/one-to-many/many-to-many messaging system that will transport your messages to and from your users.
There's a iOS API too which you can use in your project. You can download it here: http://www.xrtml.org/downloads_62.html#ios and check the documentation here: http://docs.xrtml.org/getting_started/hello_message.html#ios.
There's also a plus which is the fact that the Realtime framework is actually cross-platform. This means that you can even have your iOS players to communicate with players using Android, Windows Phone, HTML5, Flash, etc. if you decide on expanding your game to other platforms.
I hope that helps!
I'll just provide some insights on the question.
APN should never be used for synchro communication as for iOS at least, you'll never have both way communication (basically the Apple APN servers are pushing an information to the device).
You should probably play with C sockets in order to open a tunnel (depends if your game is real time or not).
Using the Apple Framework GameKit is great! But might take some time to understand all the functionnalities.
Check out Gree
https://developer.gree.net/en/
Parse:
https://www.parse.com/
Sparrow:
http://gamua.com/sparrow/
There are a few things that your talking about, there is the joining/starting of a game, and then the communication between the players. They are not necessarily related.
You can use game-center and at the same time another framework for facebook, they are not mutually exclusive (but it would be more work.)

Resources