iphone - iOS / Play audio when screen is locked but not when phone on silent mode -
i have developed chat app , problem notifications can heard if phone on silent mode (1). thing is, want notifications played when screen locked (2). checked avaudiosession categories, , seems can have either 1 of following:
- sounds disabled when phone on silent mode or screen locked;
- sounds enabled when phone on silent mode or screen locked.
how can sounds disabled when phone on silent mode, enabled when phone not on silent mode , screen locked? possible tweak avaudiosession further, or (apparently cannot) detect silent mode programmatically?
ok, fixed it. solution use audiotoolbox , system sound services. behavior of audiotoolbox looking for, i.e. respects ring/silent switch, can play in background or when screen locked.
since wanted use avaudioplayer, first check ring/silent switch playing short blank system sound (let half second sound). if completion callback made within less 0.15 seconds, know on silent mode. if not, go on , play whatever sounds have avaudioplayer.
Comments
Post a Comment