2

As per my title, i am searching any code for playing sound when my device is in silent mode. I am searching from 3days but in ios 8 and later no code is working for silent mode.

Any help would be appreciated. Please pass me any suggestion and advice as soon as possible.

Thanks

Abha
  • 1,032
  • 1
  • 13
  • 36
  • What do you use for play sound? – vien vu Nov 16 '15 at 10:16
  • NSURL *tapSound = [[NSBundle mainBundle] URLForResource: @"Tock" withExtension: @"aiff"]; AudioServicesCreateSystemSoundID((CFURLRef )CFBridgingRetain(tapSound), &soundID); AudioServicesPlaySystemSound(soundID); – Abha Nov 16 '15 at 10:21
  • You use system sound. So in silent mode it won't play. I think you can use AVplay and setting like this link: http://stackoverflow.com/questions/3740528/play-sound-on-iphone-even-in-silent-mode – vien vu Nov 16 '15 at 10:24
  • @vienvu Please can u pass me any demo which is working in ios 8 as i am trying this one also it wouldn't work – Abha Nov 16 '15 at 10:43

1 Answers1

2

You can use AVPlayer for play file sound and set:

let session = AVAudioSession.sharedInstance()
    try! session.setCategory(AVAudioSessionCategoryPlayback)
    try! session.setActive(true)

You can check my example code here:Sample

vien vu
  • 4,277
  • 2
  • 17
  • 30