iOS System Sound not being played
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?
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.
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.
链接地址: http://www.djcxy.com/p/39390.html上一篇: UITableView轻扫手势与UITableViewCell轻扫冲突
下一篇: iOS系统声音未播放