iphone battery charging indicator - iphone

Context:
iPhone is connected to the PC via cable and power indicated 100% ( the icon of the batter contains a small power plug also)
Question:
In this stage the phone is powered directly from USB or is it using the battery ?
Thanks

(From developer point of view): there's UIDeviceBatteryState enumeration that contains the battery power state of the device. Among its possible values:
UIDeviceBatteryStateUnplugged: The device is not plugged into power;
the battery is discharging
UIDeviceBatteryStateFull:
The device is plugged into power and the battery is 100% charged.
So from these descriptions follows that device does not drain battery if it is plugged into power even if it is 100% charged.

I think the device is always drawing off the battery in order to guarantee a smooth power curve i.e. the battery works like a buffer of sorts. (It also simplifies the hardware.) However, when it is plugged in, the power system continually charges the battery so the net charge on the battery never changes.
I don't think that has any relevance to programming. Usually, you only need to know if a device is plugged in if you're doing something that might take longer than the battery can last. In that case, where the power comes from while plugged in really doesn't matter.

Related

Android sensor listening when app in background

Is it possible to track motion sensor events on Android continuously, even if the app is not in foreground?
If yes - what's the drain on battery?
A client asked if it would be possible to write an app that would initiate an action if the person "falls" - which basically means continuously listening to the motion sensor for rapid movement.
First, you can definitely monitor the sensors in the background. You need to use a service for that type of application. Here is an example of someone creating a barometer data logger. There's not really any reason you couldn't use different sensors.
Second, as far as I'm aware, running the sensors continuously like that would drain the battery quickly. This presentation suggests that depending on your sampling speed, you could burn through about 4% of the battery per hour on the sensor use.
Lastly, you can definitely wake the phone and take action upon an event received by that service. See this question.

Make a simple iphone app that can connect another bluetooth device

I know some basic about iOS programming, now i want to connect my app to another non iphone device e.g. connecting to a bluetooth device that can control a light bulb on and off, or control any furnitures.
My question is, besides iOS xcode, what kind of program i need to learn in order to achieve my goal?
Is there any sources that i can learn from it?
For Bluetooth Low Energy devices, you can use the CoreBluetooth framework to access them.
For Classic Bluetooth devices or accessories that make use of the Dock connector, the protocols are not open, and joining the Made for iPhone (MFi) program is required. I do not suggest this for beginning.
My suggestion is to buy for example a Polar Heart Rate Belt that supports Bluetooth Low Energy. These use standard protocols. Sample code is available from Apple that shows how to read out the heart rate from such a device.
As soon as you have mastered the heart rate monitor example, a next step would be to acquire a programmable Bluetooth Low Energy chip (however, often, the development tools for those are rather expensive!). Those chips can be programmed with custom profiles to listen for Bluetooth Low Energy connections and then performing defined operations (lighting a LED) when writes to characteristics occur. So, you are not limited to heart rate monitors and similar devices.
Keywords that you can search for: GATT protocol, Bluetooth Low Energy, CoreBluetooth.
I know that it's a steep learning curve for beginners, but the area is pretty new. However, I can assure you that it's a fun area.
I also think that you should look in to embedded C programming for the slave device (Heart Rate Monitor)
You could get a tod Smart Beacon Development kit for ~$150 and then use BGScript to code the firmware to control the BLE device from your phone or pc. todhq.com for more info.

Using Old iPhone 3G for testing, remove the sim card?

I just got an old iPhone 3G for testing. It doesn't have a plan attached to it, but I just put in the sim card and it said it will take a while to activate.
When everyone has test devices, do you just leave the sim card out? What about when testing location based services that need to find cell towers? What do we do in situations like this? I don't want to pay for service.
You won't get anything out of the cell towers without a valid SIM card. I use my wife's old iPhone 3G for testing, and it still has the old AT&T sim card, but of course there is no service because that sim card is not on our account anymore. I always leave it in Airplane mode.
The main thing I'm verifying with the physical device is performance, UI responsiveness, and memory issues that present no problems in the simulator, but choke on this old device. The iPhone 3G is great to have on hand as a minimum baseline for that stuff.
The location-based stuff you should be able to mock up without needing any "real" data. Do a google search for "iphone" "mock location" and see what that turns up.
This looks promising:
http://rssv2.blogspot.com/2010/03/mocking-core-location.html
You don't want to have to develop with real, live data until you are in the beta stage anyways. Using real, live data during development is a huge hassle, not easily repeatable, and very time consuming. And this makes it impossible to write effective integration tests.
The iPhone has a GPS receiver, you don't need cell towers they just help speed up the process of acquiring the GPS satellites and finding your location. WiFi service will do the same thing but is not required. With no cell data and no wifi it can take several minutes to acquire GPS satellites, download ephemeris from the satellites and get a good location, but it works.
I use a 3G running 3.1.3 with no sim card for 3.1.3 testing and it works fine even for using location services, but I have wifi here.
I also use a CoreLocation simulator which allows me to simulate and repeat motion scenarios without going anywhere, it can simulate acquisition time, varying horizontal accuracy and motion. The simulator is available on github.

Debugging battery warning

I have an app that connects to an external accessory via Bluetooth. Testers have reported that the connection gets dropped when "Low Battery" alert is displayed. This was reported on iPod touch 2nd gen., so it may be peculiar to that device.
I am wondering if there is a way to run my app in debugger (connected to my computer) without charging the device. In other words, is there a way to disable USB charging of a device whose battery is not fully charged?
I have not tried it, but it is possible / likely you can do this by cutting the power cable within the usb cable.
I would buy a cheap usb extension cable (male <-> female), and carefully cut it open (remove the outer plastic in the middle of the cable without damaging the wires inside).
If you are lucky, there'll be a red cable, and that red cable will be the +5V line - if not, you'll have to use a multimeter to test which cable is pin 1 / +5V / VCC (pinout here: http://pinouts.ws/usb-pinout.html ). Once you identify it, cut that cable (and only that cable!).
Then plug your iphone/ipod into your PC using your new cable, and the iphone will hopefully still work with the debugger but will no longer charge.
As an aside, I could imagine the possibility that bluetooth is automatically disabled (or switched to a lower power mode) when the battery gets low - in which case losing the connection may be inevitable. You could try asking apple support if they are aware of anything like that.
Nope. The debugger only works when the dock cable is connected via USB to the development system, and that automatically causes the device to charge. You will have to find another way to monitor what your app is doing.
No, but you should have your user turn on logging on their test device and then send you the logs. (Or if you are that tester, turn on logging in the Settings app, under "Developer".)
Perhaps you can log the low battery message and the Bluetooth status as well.

Transferring data from a sensor to the iPhone

I have an external device (some kind of sensor) that can do a measurement. This sensor can be connected to a PC via Bluetooth or USB cable, and it also comes with it's own software.
I want to develop an App for iPhone that will analyze the data that this sensor is measuring (for example creating a graph, calculating some equations etc.).
How can I make my iPhone to "recognize" this sensor, so the app will get the data that has been measured from the sensor?
Is there any manual which explains how to code this? Our preferred way of transferring the data is via Bluetooth, so there will be no need of using cables.
Thanks a lot!
You can't use Bluetooth to transfer data unless the device is custom designed in compliance with Apple's MFi program. Only those specially manufactured devices can be recognized by an iOS app.
You can use wifi for high bandwidth data, and perhaps audio for encoding low bandwidth data.
Not sure what kind of sensor you have but PASCO scientific has a Made For iPhone Bluetooth device called AirLink2 that works with their sensors. I don't think that could easily co-opt the device for your purposes ... but it might be possible. I mention this because there's an off chance that this would useful information. I am not trying to peddle hardware here ;-)