objective c - Receive remote control events without audio -


here background information, otherwise skip ahead question in bold. building app , have access remote control/lock screen events. tricky part app not play audio itself, controls audio of device nearby. communication between devices not problem when app in foreground. found out, app not assume control of remote controls until has played audio playback audio session, , last so. presents problem because said, app controls device's audio , has no need play own.

my first inclination have app play silent clip every time opened in order assume control of remote controls. fact have makes me wonder if going allowed apple or if there way achieve without fooling system fake audio clips.

question(s): apple approve app plays silent audio clip in order assume control of remote/lock screen controls purpose of controlling device's audio? there way of assuming control of remote controls without audio session?

p.s. prefer have functionality on ios 4.0 , up.

p.p.s have seen this similar question , has gotten me brainstorming answer provided not specific need know.


note: of ios 7.1, should using mpremotecommandcenter instead of answer below.

you create various system-provided subclasses of mpremotecommand , assign them properties of [mpremotecommandcenter sharedcommandcenter].

i'm keeping rest of around historical reference, following not guaranteed work on recent ios versions. in fact, might not.


you need audio player not explicit session take control of remote control events. (avaudiosession implicit app plays audio.) spent decent amount of time playing confirm this.

i've seen lot of confusion on internet set removecontroleventrecievedwithevent: method , various approaches responder chain. know method works on ios 6 , ios 7. other methods have not. don't waste time handling remote control events in app delegate (where used work) or in view controller may go away during lifecycle of app.

i made a demo project show how this.

here's quick rundown of has happen:

  1. you need create subclass of uiapplication. when documentation says uiresponder, means uiapplication, since application class subclass of uiresponder. in subclass, you're going implement remotecontrolreceivedwithevent: , canbecomefirstresponder methods. want return yes canbecomefirstresponder. in remote control method, you'll want notify audio player something's changed.

  2. you need tell ios use custom class run app, instead of default uiapplication. so, open main.m , change this:

     return uiapplicationmain(argc, argv, nil, nsstringfromclass([rcappdel`egate class])); 

    to this:

    return uiapplicationmain(argc, argv, nsstringfromclass([rcapplication class]), nsstringfromclass([rcappdelegate class])); 

    in case rcapplication name of custom class. use name of subclass instead. don't forget #import appropriate header.

  3. optional: should configure audio session. it's not required, if don't, audio won't play if phone muted. in demo app's delegate, appropriate.

  4. play something. until do, remote controls ignore app. took avplayer , gave url of streaming site expect up. if find fails, put own url in there , play heart's content.

this example has little bit more code in there log out remote events, it's not complicated. define , pass around string constants.

i bet silent looping mp3 file work towards goal.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -