iPhone: Responding to user events - iphone

iPhone developer newbie question:
I'm looking to have my application perform an action when a user stops listening to a track on their iPhone (i.e. presses the stop button).
Is it possible to hook into these kind of events (play / pause / stop etc)? If so, which API would I use?
Regards,
Andy.

No, there's not really any way to do that. As far as I know there's no way to tell that a track has stopped, but even if there was your application would have to be in the foreground at the time of the "stop" instruction since there are no background applications (other than Apple's).

Perhaps KVO would provide the behavior you need.
Key-Value Observing Programming Guide (requires ADC login)

Related

Getting notification of iOS device usage in background

Might be i am using a wrong title but i will try to explain here what i want.
In iOS i need to implement a functionality to get notify if the user is using their iOS device.
My app will be running in background using location services and i need to find out if the the user is using their device. It is doable as i have looked into this application which is sending notifications in background to the drivers who is suing their devices while driving.
https://itunes.apple.com/fr/app/cellcontrol/id661169580?l=en&mt=8&ign-mpt=uo=2
So i need similar kind of functionality to find out if a user is using iOS device or not. If anyone of you can suggest me any approach then it would be great for me to start.
Thank you!
Note: I have tried to find out touch events in background but that is not possible as i have done some research on this.
You won't be able to receive touch events when the app is in background using public API's. However, you can do that with the help of mobileSubstrate library ( http://iphonedevwiki.net/index.php/MobileSubstrate - The MobileHooker component is the one that would be used). by hooking your process to the OS. As an example, the display recorder app in Cydia tracks global gestures while recording the screen. This will be a cydia tweak and you will need to jailbreak your device to do all that.
Coming to your specific use-case, the example app you cited should be using one of the exceptions for background applications mentioned in https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html (see the section - "Implementing Long-Running Background Tasks"), probably the one to receive updates from external accessories.

App that reacts on the voice of calling party

I need to develop an App that reacts on the voice of the caller - so the participant in the phone call who is 'not there'.. specifically:
Someone calls me and stops speaking. The app should alarm me saying "participant stopped speaking" (it does not matter if the sense of the app seems stupid for you now ;-))
My question is just - is this technically possible? Since apps normally are paused as soon as a phona call comes in. I know they can be restarted during the phone call - but can they react on the voice on the other side of the line or is this only possible for my own voice?
If you think its possible, any special things i have to know?
Thanks a lot!
tim
This is not possible. Because when any call comes in iPhone our application loose control and it goes in background.
With official SDK it is not possible to intercept any phone calls.
Hope this helps.
This is not valid IDEA using standard SDK, though you can do this using some other IDEA's one of them is CYDIA.
Thanks,

Can External Accessory be run in background for iPhone?

Sorry if it is such a dumb question or if I'm not ninja google-ing enough. I just need the answer quick.
I have an external accessory which gets data from ANT+ sensors. My question is, would it be possible that my application using the external accessory continue to run in the background, or at least send push notifications?
Thanks and feel free to downvote because I think it's very lazy of me to ask here.
According to the Apple specs your application won't receive events immediately while in the back ground but all events should be hold in a queue and sent when back foreground. Depending on the frequency your device is running and the elapsed time while staying in the background you should be prepared to get a bunch of events.
See External Accessory Programming Topics: Monitoring Accessory-Related Events
and Multitasking Support for more information.

iPhone session - timeout on inactivity

When the user successfully log into my app, session starts, after X period of inactivity the session will time out.
Now how do you detect, the user to see if his active using the application or not using it?
1) Check every on button?
2) check on screen load?
The most elegant way I've found to do this is to use a category on UIApplication that provides a sendEvent: method that resets an NSTimer (after calling its superclass implementation of course). If the timer goes off, post a notification. Listen for the notification everywhere you want to react to the timeout. Doing it this way means that you don't have to add code all through your app to reset the timer on every interaction.
Having said that, I agree with Shaggy Frog, this isn't typical behaviour for an iOS application, so it's not usually a good idea from a HCI perspective.
If you're asking "How do I define activity", you could always reset a timer after a touch event is received, whose callback triggers the "user is inactive event".
I can't speak much for your overall design choice here, as I don't think most iOS users expect their apps to behave in this manner. Think of your users and proceed with caution.
You can also check for applicationwillresignactive callback for this.

What to do when the user hit the home key and the IPhone Application exit

How do i handle the user pressing the home button at any time, while my app is still processing stuff with the server?
I have this problem both in ios3 & ios4 - i believe maybe the answers would be different because in ios4 it can last in the background.
how do you usually handle such events?
Thanks,
Itay
Typically you close all your connections, save your state so that you can renew those connections on restart, and allow your application to close. Apple's guidelines about this are pretty clear.
Check out the Multitasking section of the iOS Application Programming Guide. This tells you how to handle the various types of shutdown/suspension scenarios and how to request more time for specific allowed background operations.