I want to vibrate and flash light simultaneously.But when I Use following code i only get flash light.
if (some condition)
{
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
[self setTorch:YES];
}
But when i use only
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
my phone vibrates.
I am unable to find the issue.
May be it will useful for you
find this Gonna Vibrate the device to alert the user? Read this first
Both 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 a alert, common sense says, use function 2.
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
Related
This question already has an answer here:
iPhone - How do I know if the vibrate is on or off for iOS?
(1 answer)
Closed 5 years ago.
How to check a system vibration is on or off by pogramatically through App?
In my case UI design is like- I set a button into viewcontroller. Which funcanality is, when I press the button it's alert me the system vibration is On or Off. Here is the below code. But it's not working. It's always go with else part.
- (IBAction)checkVibrate:(id)sender {
CFStringRef state;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &state);
if(CFStringGetLength(state) == 0)
{
//off
[self Alert:#"It seems that your phone's vibration is off. Please go to your phone setting and make the vibration ON"];
}
else
{
//on
[self Alert:#"It seems that your phone's vibration is On.If you want to off the vibration, please go to device setting and make vibration Off"];
}
}
If I go through wrong way,please help me out with this topic?
No, you cannot. Apple is not providing the API to access this.
Once I saw your question, I tried to get the solution.I prepared most of the other answer in the stack overflow and other sites.All tell to use AVAudioSession
An audio session acts as an intermediary between your app and the
operating system—and in turn, the underlying audio hardware. You use
it to communicate to the operating system the nature of your app’s
audio without detailing the specific behavior or required interactions
with the audio hardware. This delegates the management of those
details to the audio session, which ensures that the operating system
can best manage the user’s audio experience.
Better Sources are
How to detect whether iPhone is vibrating or not?
iPhone - How do I know if the vibrate is on or off for iOS?
iPhone Vibration
Making the iPhone Vibration
Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?
I would like to play a sound and use the AVSpeechSynthesizer to speak out some strings. The point is that I want these to happen when the device is already locked and then some events happen which triggers them.
I've found lots of info about how to play sound on the background, but this means that playback starts when the app is active and then the playback could continue, if the screen is being locked (after the start of playback). I've done all the tricks but can't hear a sound, which is triggered when the device is locked (and app is already on the background). However this works with iOS 8.3 simulator almost out-of-the-box, but not with a device.
So how to resolve this? Should I actually use some notification stuff to produce the desired outcome? I'm not too familiar with the notifications, so is there any other workarounds or is the notifications way easier than I think?
Cheers,
Mikko
I'm creating an app where you can "send" vibrations to your contacts.
In IOS how do you set the sound for notifications from my app to vibrate, I want it to vibrate even when silent is off. Also I want the users to send custom vibration patterns, would that work or can you only play a sound once. It should work even when the app is not in background.
Try This Code :
1) AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);
2) AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
I'm building a VoIP app on iOS and I'm using the AVAudioSession category of AVAudioSessionCategoryPlayAndRecord, which is recommended for VoIP apps that need to constantly play and record audio.
However, when the user switches their iPhone ringer to silent mode, the VoIP application will still play sound for an incoming call. This is not desired behavior.
Is there a way to prevent the incoming calls from playing audio when the user has their phone on silent, but still allow them to answer the call and have audio resume?
If you take a look here at the docs for AVAudioSession Categories, you can see that AVAudioSessionCategoryPlayAndRecord unfortunately does not obey the silencing of a phone, as seen below:
Your audio continues with the Silent switch set to silent and with the screen locked. (The switch is called the Ring/Silent switch on iPhone.)
If you want the audio to stop when you turn the phone to silent, you should use AVAudioSessionCategoryAmbient.
I think I found a solution that works for a VoIP application. If the phone is set to silent, I wanted the phone to show an alert and vibrate instead of playing the audible ring.
I can solve this by using local notifications and moving the sound out of the application and adding it to the notification itself. By specifying a sound file as part of the notification, iOS will handle whether it should play the audio or vibrate the phone. This is determined by the position of the Ring/Silent switch on the side of the phone.
Here's an Apple article on adding a sound to a local notification.
There seem to be a few threads floating around this topic but no definitive answer: if a user loads the app with sound enabled but later mutes his/her iPhone, how can we detect this in PhoneGap? Is there a callback for this event? The docs don't seem to list anything.
A second, related question: how to detect the status of the mute button? If someone has mute enabled, how do you detect this to avoid playing audio? The media.play() method only seems to have an option concerning whether to play audio when the screen is locked.
Thanks!
I wanted our app to don't play sounds when the iPhone is muted.
After hours of searching I decided to try with the following parameter and works as expected:
myMedia.play({ playAudioWhenScreenIsLocked : false });
The documentation doesn't say anything that this parameter will make the sound to not play when the iPhone is muted, but it behaves like that.
I'm using PhoneGap 2.6.0 and the docs says:
Pass in this option to the play method to specify whether you want to
play the audio of the media file when the screen is locked (this
defaults to true if not set). If this is set to true, it will ignore
the state of the hardware mute button.
Bad documented?