How to receive single tap and hold Remote-Control Event with iOS? - iphone

I'm looking for my app to listen for the single tap and hold of the play/pause button on headphones for iOS devices. Currently, the behavior is to start Voice Control (on my iPhone 4).
The event list for remote control events allows for getting the double tap and hold (BeginSeekingForward) and the release (EndSeekingForward), but I'm looking for the single tap and hold which currently activates Voice Control.
Is there a way for my app to override Voice Control and listen for the single tap and hold?

You can add in a UILongPressGestureRecognizer to your UIButton and work from there.
If you want to prevent your other method from being called, you'll also need a UITapGestureRecognizer that counts taps and sets a value to true when it receives a second tap and another method (Check from your UIResponder touch* methods) for a touch release and set the value back to false.
Using that value, you can check with the UILongPressGestureRecognizer to see if the user double tapped or not.
Alternatively, you could also just have the value set to false upon a touch to the button that doesn't have a tap count of two.
Hope this helps!
EDIT: You cannot override the headphones (as far as I know) without jailbreaking the device. Normally you should never have to code for people interacting using the Apple headphones, since that would severely reduce the market and usability of your app. If someone were to forget their headphones, for example, they could not utilize your app. Its just something to think about. You don't want to limit your apps accessibility too much.

Related

UIAccessibilityAnnouncementDidFinishNotification not Firing when Swiping to another element

I am using UIAccessibilityPostNotification and UIAccessibilityAnnouncementDidFinishNotification in my app. According to this link, the notification should be posted either when the announcement finishes successfully or it does not (i.e. the user swipes to another element on the screen).
UIAccessibilityAnnouncementDidFinishNotification expects an NSNotification dictionary as a parameter from which you can determine the value spoken and whether or not the speaking has completed uninterrupted. Speaking may become interrupted if the VoiceOver user performs the stop speech gesture or swipes to another element before the announcement finishes.
It works fine if the announcement finishes, but if I swipe or tap the screen before it finishes, no notification is posted. Any thoughts on why this might be? Could it be a bug? If so, any suggestions on workarounds? I have text coming in that needs to be read sequentially so am using this to synchronize. Even if I could somehow reset my speaking flag to 0 when the user taps the screen/does anything, that would be great.
Create a custom view and that custom view needs to implement the protocol UIAccessibilityFocus
- (void)accessibilityElementDidBecomeFocused
- (void)accessibilityElementDidLoseFocus
- (BOOL)accessibilityElementIsFocused

iPhone HARDCODING a swipe

Basically, we either have remote access to the iPhone or the phone is connected to a network where we can control the phone (send it messages etc.) How can I simulate a swipe without touching the actual phone? I know there are Swipe Recognizers, but I haven't found a way to HARDCODE coordinates to simulate a swipe; for example, without touching the phone, perform the swipe to unlock.
A swipe is input. You'd normally recognize the swipe, either with a gesture recognizer or by handling the touch directly, and then perform some sort of action. If you want to simulate a swipe, just perform the action that would be performed if the user made the equivalent gesture.
For example, if a swipe would normally switch to a different view, simply call the method that switches to that view. If possible, do it with animation so that the user has some visual indication of what's going on.
I'm not entirely sure that what you are trying to do is possible, unless maybe with a script in the Automation instrument. However, if the iPhone is jailbroken, you could install Veency and connect the phone through any VNC client and interact with it that way.

Programming background behavior when iPhone is locked and user presses power button

Sorry, I am new to iPhone development and my google searches have failed me, so I have had to resort to posting a potentially idiotic question on SO.
I would like to write an app that, when suspended, performs an action when the user presses the home or power button (presumably to unlock the phone). I read the section in the iOS App Programming Guide's App States and Multitasking and the "Processing Queued Notifications at Wakeup Time" discusses handling queued events upon waking up. However, this isn't what I'm after.
I'd like to know if it is possible to:
From the phone sleeping state (I couldn't find a document for phone states, so I am talking about the case where the user presses the power button to turn off the screen), I would like my app to be ready to respond to the event where the user presses the power or home button (to unlock the phone)
I would like my app to respond to the event that occurs when the user unlocks the phone. I found an answer here that's close.
I don't want any funkiness when calls come in, get ignored, etc. :)
From what I can tell, it's a very gray area in the API around locking and unlocking, and I'd like to verify whether or not I'm wasting my time trying to do this.
It looks like I can use the accelerometer to detect when the phone is locked, but I also assume that I won't be able to count on this behavior in all future versions of iOS.
EDIT - I think I can handle the locking and unlocking requirements by assuming that the application has to be running at the time the phone is locked and unlocked, but I still cannot figure out if it is possible to determine #1 above, which is that the power button has been pressed and the unlock screen is displayed. Likewise, I'd like to know if the power button has been pressed again and is no longer displayed (i.e. screen is off).
All of the behaviors for your app being suspended/backgrounded are in the document you referenced. The AppDelegate will receive these messages and pass them on to whatever view you want to listen for them.
-applicationWillTerminate
-applicationWillEnterBackground
-applicationDidBecomeActive
-applicationWillResignActive
You can set up a notification observer in your view if you would like the view to be notified of any of these events. Then just override them or set up a custom method to do any work that needs to be done.
While the Apple docs might be a little foggy at first, all the information is in there to let you know which state your app will go to and how it will be handled. It is up to you to figure out what your app needs to do for each of these events. Hope this helps.

Flash cs5 iOS holding down?

Hey, I was wondering if there was an event or something that can check if my user is holding down a button? (for iphone, iOS)
The Event class is TouchEvent. You'll need to toggle the touch state in a variable if you want to keep the fact someone is pressing down after the fact (of the event).
You can use MouseEvent if you need/desire a single touch point. Though you still need the variable.
You need to set Multitouch.inputMode to MultitouchInputMode.TOUCH_POINT in order to turn on touch events on the iPhone. Unfortunately, you can only test touch/gesture events on the iPhone itself. (MouseEvent and TouchEvent are virtually identical in use: MOUSE_DOWN = TOUCH_BEGIN, MOUSE_MOVE = TOUCH_MOVE, TOUCH_END = MOUSE_UP. The main difference is that you can only have one "mouse" yet multiple touches.)
Personally, I use MouseEvent to test on the machine, with an if-then setting up TouchEvent listeners if Multitouch.supportsTouchEvents is true (which it only is on the iPhone/Android).
If the button is a Cocoa Touch UIButton, you can easily connect a number of its gesture events from Interface builder to code Xcode IBActions (where you write the appropriate methods).
How your project would connect to flash, I am not sure. Give us more details and perhaps someone can better help. ;)

IPhone SDK Home Button

Is it possible to override the default behavior (close app) of the Home Button? And if how do you do that?
well, there's a reasonable alt to the need to detect if the Home button was tapped. i'm currently working on just such a scenario.
my app allows user input (into UITextViews). a customer has asked for an "autosave" feature where, should they (accidentally) tap the Home button during data entry, could i still capture the data entered and save it.
my testing of the sequence of viewWillDisappear in the view that is collecting the data and applicationWillTerminate show viewWillDisappear getting called before applicationWillTerminate. now i fully appreciate that this is the architected sequence Apple intended, BUT this sequence also precludes setting a simple Boolean in applicationWillTerminate to let the particular viewWillDisappear know that it is disappearing specifically due to applicationWillTerminate.
so the issue still stands. how can a UIView detect that it is disappearing specifically as a result of the app terminating?
Even if it is possible, your app will probably not be approved by Apple.
Are you planning this feature for your own private App or do you want to distribute it later on?
The home button is probably the most critical button on the device on not a good idea to change