How to show popup question to start tracking a stair stepper exercise on the Apple Watch? - ios

Is there a way to detect activity in the background using my app like Apple does it?
Currently there's no way to calculate stairs climbed by the user while using a stair stepper machine using the Apple Watch/iPhone. We want to be able to detect activity in the background if our app is installed and ask them "It looks like your climbing stairs on a stair stepper". The only thing I can think of is to do a Background scheduler event, but the shortest period allowable is every 15 minutes which is almost at the end of any work out with a stair stepper machine.
Is the Apple Watch using inaccessible private APIs to achieve this behavior? Or is there a way we can achieve it too?

I have never tried it but I think it can be done with location region monitoring and some ML.
Keep track of where the user is when they trigger workouts, and the time. Maybe even heart rate and any other data that might give you clues.
When you get notified that the user is in that spot, check for activity and/or clues with ML and send the notification.
The watch only seems to send that notification if it knows the area where you are is a workout area and the right time.
Apple has ML videos where the user can train a model on device. I think their sample shows a restaurants app where depending on time, day, and location you can suggests restaurants to a user.

Related

How to implement a pedometer in CoronaSDK

I'm trying to create a pedometer for an app that I'm coding in CoronaSDK, though I'm not really sure where to start.
I know that I need to create an algorithm/equation from the accelerometer data that is accessible.
(https://docs.coronalabs.com/api/event/accelerometer/index.html).
Any help or hints with an algorithm would be appreciated.
Here's what Coronalabs says about this:
Corona SDK does not have any API's or any plugins that can count
steps. However you do have access to the acceleromenter which gets you
the raw data on the device's movement and compute steps yourself, but
this will only work while the phone is awake and the app is in the
foreground. Corona SDK is not designed to run in the background. There
is an assumption that there is a screen to draw to each frame.
We do have a product called Corona Enterprise that lets you talk to
other native SDKs. You could use it to collect your native data and
in theory have it run in the background and when the app wakes up, send the collected data to the Lua/Corona portion of the app to
display.
So if this doesn't stop you you could try to implement this:
Opening the Black Box: Publishing Pebble’s activity-tracking algorithms where they basically look for the most rhythmic frequency within a 5 second interval. If the calculated score is above a certain threshold it's considered running or walking.

Is it possible to get the current healthkit status of an iOS user?

For instance if I wanted to respond to when a user was walking/running/sedentary/bicycle/etc is that possible in current SDKs?
Lucked upon the answer. In CMMotionActivityManager:
The CMMotionActivityManager class provides access to the motion data stored by a device. Motion data reflects whether the user is walking, running, in a vehicle, or stationary for periods of time. A navigation app might look for changes in the current type of motion and offer different directions for each.

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.

Using location based push notifications on iOS

I am looking on developing a tourist application for a city, where when the user is near to a "place of interest" he could get a push (local) on his device.
For example, I would add 100 POIs on my app, and a 100 messages for every POI to show when the user is in range, e.g. "You are close to the Cathedral of.."
Is this scenario possible? Is it possible to check the users position e.g. every 10 minutes even when the application is killed, and when in range fire a local push? How much battery would it drain? If the user closes the GPS would it try to use 3G/wifi signal to get the position?
If yes could you guide me the right way on what I should read on the subject maybe some tutorials and articles?
that's indeed possible. You could use the aforementioned technique outlined in this post. You can extend this with using CLLocationManager:: startMonitoringSignificantLocationChanges to restart the process of listening to locations after the app has been killed. Depending on your accuracy needs there are many other optimizations that can be done regarding battery life, like checking more frequently when a user speeds up etc.
I have developed a library that handles these details for you (for both Android and iOS). The download includes an example application that demonstrates how to use it. Feel free to check it out.
Yes,that is possible.you need to have some "places" (co-ordinates or addresses) stored on theapp locally. Proximity to a stored "place" can be checked by Reverse geocoder.
Check this Wonderful SO Question , very similar to yours
This might be too late for your question, but for anyone else that needs it. GeoFencing is a good option.
Here is a video explaining what geofencing is http://academy.pulsatehq.com/7-things-about-geofencing
And if you are using Ionic platform, here is the link to the plugin
https://github.com/cowbell/cordova-plugin-geofence
GeoFencing will solve exactly your problem. Just create a bunch of geofence located at these tourist sites and when user enters within certain radius of these locations, user will get a notification.
Good luck
When the app is killed, what exactly would be receiving the location updates?
When in the background though, you can set up location updates based on both proximity and time.
Check How do I get a background location update every n minutes in my iOS application?
As for GPS vs. 3g/wifi, the user has the ability to either allow location services for an app, or not. iOS will then handle whether GPS or cell signal will be used to determine position. Read about the significant-change location service here. Using the significant-change service will use more cell location than GPS lock to determine position, and vice-versa for the standard location service. Also look at location accuracy to learn more about conserving battery.

Geofence API for iOS 5

I want to build an application that can set up a set amount of geo-fenced square regions across town, I know I could achieve this by enabling location in the background, and check those coordinates to determine if they are in my area of interest.
But that would mean receiving many notifications from the system and would hit the battery performance.
Instead I wondered if there was a new API or possibly an upcoming one that would let you set a geo fence and only be notified by the system if you're inside of that or close by, rather then monitor your location constantly.
Is that possible ?
I found the following question, but I can't find much else:
http://www.quora.com/Is-the-geo-fence-functionality-built-into-iOS5s-Reminders-application-available-as-a-public-facing-API
It would seem to me that there is something more to geo fencing then tracking the GPS and comparing to an array of points of interest. If I set the reminders app to remind me that I have to walk my roommates dog tonight when I get in, then I can see the location icon at the top of the screen.
If I open the multitasking bar and remove reminders, the location icon persists, indicating the phone is tracking me, but it's an independent task to the reminders app.
If I set up an application with background location tracking, and remove from multitask bar, the location icon disappears with the application. This makes me believe that there is or will be an API for geo fencing coming for iOS 5.x, this would allow apps to post an array of coordinates to the system and receive local notifications based on the proximity to those points.
Does something similar exist or not yet ?
Thanks
UPDATE FOR FUTURE USERS
There seems to be a limit of 10 regions per app that can be monitored at any time (my personal testing), as this is a shared resource.
Apple Documentation extract:
You should always be judicious when specifying the
set of regions to monitor. Regions are a shared system resource and
the total number of regions available systemwide is limited.
You should look at the startMonitoringForRegion:desiredAccuracy: method on CLLocationManager.

Resources