my question is that i want to write a simple code in xcode, by which if i bring another iphone closer to mine, and make contact... then certain function is called ? help ..
-
What do you mean by «make contact»? You should maybe use bluetooth for that purpose. – Macmade Mar 11 '10 at 11:26
-
Check GameKit : http://stackoverflow.com/questions/1049393/gamekit-in-iphone-sdk-3-0 – Tuomas Pelkonen Mar 11 '10 at 11:26
-
1You say "a simple code in xcode" - yet this is something that isn't simple. There are so many factors at work here, what technology will you use? How close is "closer to mine"? Will you want to use Bluetooth? GeoLocation? You need to research your project, refine your requirements and at least make an attempt before you get any decent answers from the people here. – Jasarien Mar 11 '10 at 11:28
-
this would be done by using UIAccelerometer, but i can figure out how ? – Sawera08 Mar 11 '10 at 11:40
-
by make contact i mean if two phones touch each other, or strike – Sawera08 Mar 11 '10 at 11:42
-
You're looking for functionality like the 'Bump' app, right? – conorgriffin Mar 11 '10 at 14:42
2 Answers
It is difficult to determine one iPhone striking another.
You might be tempted to use the geolocation tools, but they could only tell you when the two devices are within a few meters, and that's the best case scenario. What I would do would be to detect a sharp bang using the accelerometer and take note of the time at which it occurred, use the bluetooth communications provided by GameKit (perhaps) to ask connected devices if they had an equally sharp hit at this exact moment in time. If they did, then it could be likely (depending on how many devices you are tracking etc.) to adequately tell when one device 'strikes' another.
But this will only work well with significantly percussive movements, and you may need to do complex filtering of the accelerometer to refine your detection method.

- 217
- 2
- 10
You want the Gaming Kit. It has relatively simple means of handling peer-to-peer communications.

- 64,370
- 15
- 118
- 145