-3

I am fine with Jailbreaking the phone if it helps.

I'm trying to make my iPhone 4s ping its current location to a server every time the volume is pressed.

Here are the main steps for the desired functionality

  1. Press the volume button. Ideally, this should only trigger the next event if the phone is locked.

  2. The iPhone gets it location and makes a HTTP POST to send it to my server.

I haven't actually done any iOS programming, but I'm wondering if this is possible and what are the main steps I would take to begin learning the technologies required and building.

Thanks.

maxple
  • 311
  • 2
  • 6

1 Answers1

2

You should be able to detect the button press programmatically, and from that point you can handle it however you'd like. More information about that already exists in a question/answer made previously in this year:

Detect Volume Button Press

From here, in order to get the location, you'll have to use the CLLocationManager class. There is documentation on Apple's developer website that actually shows you exactly how to do this task.

Furthermore, you'll want to check out the Apple developer page for using NSURLConnection, and find the section about making an HTTP POST request: NCURLConnection Documentation

In order to be able to do this, you would likely have to have knowledge of: Swift/Objective-C, iOS, PHP, and HTTP. You also probably want to have the determination to do a bit of research. You won't be able to get this all done by copying and pasting code. However, you shouldn't have to jailbreak the iPhone. Just some solid programming work will get you the functionality you want.

Hope this helped.

Community
  • 1
  • 1
Michael Fourre
  • 3,005
  • 3
  • 15
  • 26
  • Thanks so much! Out of curiosity, at which stage does PHP become relevant? And just to clarify, could this potentially work even when the phone is locked and the app backgrounded? – maxple Oct 07 '15 at 19:13
  • You'll probably want to use PHP (or a similar web language) in order to handle the information that you send to your server. I'm just assuming that you'll want to do something with the data you receive instead of just dumping it in a text file. When the phone is locked/app is in the background, I can't confirm but you should check out info about the app lifecycle to understand permissions in each state: [Here](https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/StrategiesforHandlingAppStateTransitions/StrategiesforHandlingAppStateTransitions.html) – Michael Fourre Oct 07 '15 at 19:27
  • You might be able to use a Private API in iOS to get a more desirable functionality, but then you won't be able to upload that app to the App Store. However, it seems like you may not even be interested in putting it in the App Store, so that could be worth researching. Apple expounds upon their App Store guidelines: [Here](https://developer.apple.com/app-store/review/guidelines/) – Michael Fourre Oct 07 '15 at 19:31
  • "However, you shouldn't have to jailbreak the iPhone.". Your answer doesn't address the issue of doing all of this if the OP's app is in the background (or not running). In order to overcome those hurdles, then the app may need to be jailbroken, depending upon the requirements of the app. – Gruntcakes Oct 07 '15 at 20:50
  • @HerrErnstvonFlübbergrübber You're right, it doesn't answer the question in the event that the app should be able to complete those functions while in the background. I only mentioned that since the OP referred to this functionality as an "ideal", so my response assumed it as optional rather than required. Depends on what he really needs. Thanks for mentioning it; there may be an option with a jailbroken device. – Michael Fourre Oct 07 '15 at 21:35