How do you get the charge status of a connected iPhone from the Mac? - iphone

In iTunes, you can see the charge status of the iPhone currently connected:
This updates as the phone charges, and even shows when the phone is done charging.
Is there a way I can discover the charge status programmatically from the Mac? Any programming language or API is fine.

I would recommend setting up a bonjour service in an App on the iOS device to communicate with the computer. The app will then communicate the changes in the batter status using the batteryMonitoringEnabled property of UIDevice. Take a look at the samples code here.
BatteryStatus Sample Code
And here is the class reference
UIDevice Class Reference
And finally Bonjour programming
Bonjour programming guide

As far as I know, the only official way to communicate with the iPhone over USB/Bluetooth is by signing up to the "Made for iPhone" program:
http://developer.apple.com/programs/mfi/
Unfortunately the documentation seems to be closed to registered members so I can't find out if the API for this is public or private. You could contact Apple to check before applying.
UPDATE : As mentioned, this might not work for Mac/PC <-> iPhone communication over USB. There are several apps that do things with the phone over USB (although usually for reading/writing files). I'd start by looking at the source code of those:
http://code.google.com/p/iphonedisk
This should put you at least in a position where you have a connection to the device and are able to send/receive commands. Everyone who's ever done this sort of thing has had to spend time reverse engineering the thing :) The jailbreak community might be able to provide some insight too, although having to actually jailbreak the device is probably unacceptable.

Related

Peer-to-peer communication between iOS devices

I am trying to prototype a solution to a problem and am currently exploring multiple routes I could try. Is it possible for one iOS device, running a certain app, to communicate directly with another iOS device, running the same application - without the need to be on the same LAN?
Solutions I am currently investigating are using Bluetooth and ad-hoc wireless connections.
Ideally, the application when installed would ask the user for the required permissions, and then would accept and/or send data to/from another client after a handshake had happened.
My concern with Bluetooth is that 'pairing' would need to happen with every device, rather than happen in the background once the user has installed the app. I have a feeling what I am talking about isn't possible from what I've been reading elsewhere on Stackoverflow.
Take a look at Bluetooth Low Energy.
https://developer.apple.com/library/ios/#samplecode/BTLE_Transfer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40012927
Here is another example,
https://github.com/KhaosT/CBPeripheralManager-Demo
You might also want to look into GameKit and peer-to-peer connectivity there.
I can't tell you anything about it, but you might try looking at iOS 7. If that's an option, I'd take a look. Can't talk about what it is because of NDA though.
Depending on what you need to communicate, you could try checking out this project, which lets you share arrays of strings between iOS devices over Bluetooth LE.
You don't need to "pair" the devices and it can still communicate while the app is in the background. SimpleShare
Hope it helps!
From the documentation of MultipeerGroupChat:
MultipeerGroupChat sample application utilizes the Multipeer Connectivity framework to enable nearby users to discover, connected, and send data between each other. This sample simulates a simple chat interface where up to 8 devices can connect with each other and send text messages or images to each other. Here you will learn how to bring up framework UI for discovery and connections and also how to monitor session state, listen for incoming data and resources, and send data and resources.
This is an excellent example at developer.apple.com here is the link
https://developer.apple.com/library/ios/samplecode/MultipeerGroupChat/Introduction/Intro.html
Also this tutorial from Ralf Ebert demonstrates how to use Multipeer Connectivity framework for peer communication should help you.
https://www.ralfebert.de/tutorials/ios-swift-multipeer-connectivity/

iPhone Bluetooth Communication Examples

I've been trying to find examples on communicating with bluetooth devices on iOS and have been coming up short. As I understand it SPP is not yet supported. At the simplest level, I'd like to send a simple 1 or 0 signal to the bluetooth device I'm creating. (It's a bluetooth switch that would turn something on and off). Is there a way to cleverly do this through the HID or HFP profiles?
The short answer to your question is that you can't connect to an arbitrary Bluetooth device you may happen to have, you can only connect to a Bluetooth device that has come through Apple's licensing program (i.e. the "Made for iPod/iPhone" label). From Apple's documentation:
Q: [The External Accessory framework allows] my application to communicate with Bluetooth devices. So why doesn't my application see the Bluetooth accessory sitting next to my iPhone?
A: The External Accessory framework is designed to allow iOS applications to communicate only with hardware accessories that are developed under Apple's MFi licensee program.
So there is no public API for accessing an arbitrary Bluetooth device from within iOS: you have to go through the External Accessory Framework to communicate via Bluetooth, and the EAF's mission is "communicate with MFi devices," not "communicate with arbitrary external devices." A sufficiently ingenious developer could probably hack something in there, but -
it's a non-trivial undertaking
you are spectacularly unlikely to get past the App Store approval process
So there's just not much percentage in it - the effort of doing so is unlikely to reward you.
If there already exists an MFi device that can be coerced into doing something that you want, that's probably your best chance - short of going through the MFi approval/licensing process yourself, of course. If you want to do so, have at it and good luck.
I'm answering this question late because Zeroxide's answer is incorrect (you can use a random Bluetooth keyboard with your iOS device because Apple implemented that connection, which is different from giving you a public API path to doing likewise) and I find Rokridi's answer to be incomplete-though-headed-in-the-right-direction.
Edit: A caveat has since been added to the linked Apple page about Bluetooth Low-Energy devices. So there's a loophole, but it's not a big one because very, very few Bluetooth LE devices have actually been produced as yet.
As far as i know, if your external device is non iOs device then you should use External Accessory Framework to communicate your application with it. Threfore, you external device should be certified by Apple through the Made for Ipod program (MFI). Hope this helps.
If you want to use classic Bluetooth (not BLE), then you have to first PAIR the iOS device to the Bluetooth device (in Settings). If you can't do that then you can't communicate with it with your app.
NO. whether device is MFi certified or not, you can connect device to iphone if bluetooth profile is HFP, or HID's (ordinary profiles. not iAP profile). Think about bluetooth headset or keyboard. does it need MFi mark on it to use? NO. Never.

Sending data via bluetooth on Iphone (iOS 5.x)

I have been searching and searching, but found nothing yet. Is it really true that there isn't a straightforward way to establish a BT connection from my iPhone to another (3rd party) BT device, i.e. an audio receiver. I know this is possible through the OS (I own a Belkin BT music receiver that works this way - it appears in Settings and from there I can connect to it). Note that I am not interested in pairing to iOS-devices, but an iPhone and my custom made hardware.
I've managed to find Google's BTStack at code.google.com, iBlueNova, Celeste and more, which all must be run through Cydia or similar and also I stumbled upon Apple's MFI-program, which seems fairly complicated.
Does anyone have any experience with bluetooth and iOS, if so, how and where do I get started?
If one might be interested, the project I am developing involves a piece of hardware with a BT device attached on it. The app should be able to send simple commands via bluetooth (basically just ASCII characters) to the device, which will react depending on what it receives.
If you are developing accessories that need to connect to iOS devices and want to use your own communication mechanism then your only option is to join the Apple MFi program.

How can an iPhone access another non-iPhone device over wireless(Bonjour)

i go device(my own construction with openwrt on it) that is configurated as infrastructure of my local network. I want to see that device from application on Iphone and after that send to it some data(simple short string) and recive. I read something about Bonjour but my device doesn't have that and i don't know if (and how)i can install it on my device. Any help or suggestion?
You would need to write your own Bonjour implementation on this other device. It's not too difficult, and Apple provide some good documentation on Bonjour here.

Is file transfer possible to iPhone 3.0 via Bluetooth or not?

Is it possible to transfer files of a bluetooth device, lets say a digital pen (e.g. Nokia or Logitech io2) to the iPhone? I am interested if I could do a native application that could somehow get that binary file sent by the digital pen and do something with it.
I am used to rfcomm and obex but I can only find inconclusive results when I search for that and the support in the iPhone SDK... Any ideas?
No, on a normal iPhone you are totally unable to do this.
However, it is totally capable and the functions most likely exist, but Apple doesn't want people using them so you aren't going to find anything in their documentation. An extremely large number of these functions exist. If you wrote an app containing one of these functions, Apple wouldn't let it into the app store.
They're extremely and reasonably concerned about safety. Bluetooth isn't exactly known for being secure in any form.
Look at the EAAccessory reference.
It seems like it should be possible to write a custom app that talks to any bluetooth device - you'd have to implement the file transfer protocol yourself, but now that apps are free to talk to bluetooth devices I don't think the API will prevent you from doing what you stated you want to do.
To my knowledge, no – the iPhone OS does currently not support filetransfers via Bluetooth. I think you will have to jailbreak the software to get enough access to the Bluetooth stack to pull it off.
It is very telling that even if you have Bluetooth turned on in your iPhone, it does not show up on other devices when searching for units to transfer files to. I suppose it's saying something in its Bluetooth signature that tells other devices that it doesn't receive files.