3

I am new to coding applications, and I have created a simple app that plays a sound. I have tested it and it works just fine. However, I want to play the sound on silent mode.

Here is the code:

#import "ViewController.h"
@interface ViewController ()
@end

@implementation ViewController

-(IBAction)Button1Sound:(id)sender{
    AudioServicesPlaySystemSound(Button1);
}

- (void)viewDidLoad {
    NSURL *Button1Sound = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"nobody" ofType:@"m4a"]];
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)Button1Sound, & Button1);

    [super viewDidLoad];
}

@end

I have looked at other questions online, and they said to add this line of code:

[[AVAudioSession sharedInstance]
        setCategory: AVAudioSessionCategoryPlayback
              error: nil];

I am not sure where to put it or if I am using the right syntax. I am using an audiotoolbox framework as well.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    You might be able to get around that by playing it like it was music instead of audio, but I suggest you don't do that. People use silent mode for a reason and playing sounds when the phone is in silent mode would be annoying at best. – EmilioPelaez Dec 01 '16 at 00:26
  • I was just curious how it would be done. –  Dec 01 '16 at 00:31

1 Answers1

0

When in silent mode, unless the user explicitly initiates sound playback, such as media playback, it is in violation of the Human Interface Guidelines (HIG) and is grounds for the app being rejected.

Per the HIG:

Silence. People switch their device to silent to avoid being interrupted by unexpected sounds, such as ringtones and incoming message sounds. They also want nonessential sounds disabled, including keyboard sounds, sound effects, game soundtracks, and other audible feedback. When the device is set to silent, only explicitly initiated sounds should occur, such as audio during media playback, alarms, and audio/video messaging.

If you feel your need is not in violation, see this post for a solution.

Community
  • 1
  • 1
Jeshua Lacock
  • 5,730
  • 1
  • 28
  • 58