iOS System Sound not being played
Asked Answered
T

2

7

I am trying to implement playing of system sound in my app running on iOS 10.3.1 The problem i am experiencing is that when i am in viewDidLoad, when the app is being debugged, the sound is being played. When the app is running normally, it is always vibrating.

AudioServicesPlayAlertSoundWithCompletion(1107, nil);

When i want to use this same system sound, in a specific location in the app, the appropriate location which should produce sound, it doesn't do anything, no sound nor vibrate in debugging mode or normal run.

I don't see any errors nor warning when the app is running. EDIT* Added some code where i use it:

- (void)viewDidLoad
{
    [super viewDidLoad];
    AudioServicesPlayAlertSoundWithCompletion(1107, nil);
    //AudioServicesPlayAlertSoundWithCompletion(1100, nil); (same)
}

This always does only vibrate, doesn't matter if turned on the ringer, or whether it is connected the phone to Xcode or not.

I have this imported, if it means anything:

#import <AVFoundation/AVFoundation.h>
#import <CoreLocation/CoreLocation.h>
#import "CoreLocationController.h"
#import <AudioToolbox/AudioServices.h>

Anyone can help?

Tzar answered 10/5, 2017 at 0:1 Comment(13)
Are you using device or simulator?Scherman
device, 6s, connected to Xcode for debugging.Tzar
can you share code?Scherman
does it have to be the playing of the sound to the main queue? that is the only thing i can think of. The places where i want to use the system sound, that it is not on the main queue, but in viewDidLoad, i don't see a reason why doesn't work.Tzar
This might seem too obvious, but have you checked whether or not your volume is turned up?Vincent
Yes, i have it switched to the on position, and i checked when i lock the phone, can hear sound.Tzar
Is there any settings in the settings, that i have to specify for system sound? Maybe i missed something there.Tzar
AudioServicesPlayAlertSound(1107) i tried that in viewdidload and it worked.Scherman
yes, i have it in another application, and it works too, but in this current one, i can't seem to find the issue why it is not working.Tzar
xcode 8.3.2, and deployment target 9.0Tzar
Ok, so some improvement, now in viewDidLoad, it plays. But then in a specific function, it doesntTzar
any suggestions? Can it do anything with AVAudioSession? since i am using thatTzar
Check in that specific method which thread you are on?Scherman
M
3

You can find some interesting stuff in the headers of the Framework AVFAudio.

Categories

Headers

You should check this post, I think it might help you.

How to play Alert Sound

1) AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
2) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

Both of the functions vibrate the iPhone. But, when you use the first function on devices that don’t support vibration, it plays a beep sound. The second function, on the other hand, does nothing on unsupported devices. So if you are going to vibrate the device continuously, as an alert, common sense says, use function 2.

Mhd answered 15/5, 2017 at 11:36 Comment(0)
A
0

There are two volume buttons (volume up and volume down). Beside the volume up button, there is a toggle(switch) button, which is actually a mute button.

Aggie answered 17/5, 2017 at 6:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.