Vibrate when playing sound as alert

// FREEBIE
pull/1/head
Michael Kirk 6 years ago
parent d7fcac8a5a
commit d3be2b4a3b

@ -25,6 +25,7 @@
@property (nonatomic, readonly) NotificationType notificationPreviewType;
@property (nonatomic, readonly) NSMutableArray<NSDate *> *notificationHistory;
@property (nonatomic, nullable) OWSAudioPlayer *audioPlayer;
@end
@ -238,7 +239,8 @@
} else {
if (shouldPlaySound && [Environment.preferences soundInForeground]) {
OWSSound sound = [OWSSounds notificationSoundForThread:thread];
[OWSSounds playSound:sound quiet:YES shouldRespectSilentSwitch:YES];
self.audioPlayer = [OWSSounds audioPlayerForSound:sound];
[self.audioPlayer playAsForegroundAlert];
}
}
});
@ -343,8 +345,8 @@
} else {
if (shouldPlaySound && [Environment.preferences soundInForeground]) {
OWSSound sound = [OWSSounds notificationSoundForThread:thread];
// We play the "quiet" variation of sounds if possible for notifications in the foreground.
[OWSSounds playSound:sound quiet:YES shouldRespectSilentSwitch:YES];
self.audioPlayer = [OWSSounds audioPlayerForSound:sound];
[self.audioPlayer playAsForegroundAlert];
}
}
});

@ -48,9 +48,6 @@ typedef NS_ENUM(NSUInteger, OWSSound) {
+ (nullable NSString *)filenameForSound:(OWSSound)sound;
+ (void)playSound:(OWSSound)sound shouldRespectSilentSwitch:(BOOL)shouldRespectSilentSwitch;
+ (void)playSound:(OWSSound)sound quiet:(BOOL)quiet shouldRespectSilentSwitch:(BOOL)shouldRespectSilentSwitch;
#pragma mark - Notifications
+ (NSArray<NSNumber *> *)allNotificationSounds;

@ -17,8 +17,6 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
@property (nonatomic, nullable) OWSAudioPlayer *audioPlayer;
@end
#pragma mark -
@ -209,27 +207,6 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob
return url;
}
+ (void)playSound:(OWSSound)sound shouldRespectSilentSwitch:(BOOL)shouldRespectSilentSwitch
{
[self.sharedManager playSound:sound quiet:NO shouldRespectSilentSwitch:shouldRespectSilentSwitch];
}
+ (void)playSound:(OWSSound)sound quiet:(BOOL)quiet shouldRespectSilentSwitch:(BOOL)shouldRespectSilentSwitch
{
[self.sharedManager playSound:sound quiet:quiet shouldRespectSilentSwitch:shouldRespectSilentSwitch];
}
- (void)playSound:(OWSSound)sound quiet:(BOOL)quiet shouldRespectSilentSwitch:(BOOL)shouldRespectSilentSwitch
{
[self.audioPlayer stop];
self.audioPlayer = [OWSSounds audioPlayerForSound:sound quiet:quiet];
if (shouldRespectSilentSwitch) {
[self.audioPlayer playWithAmbientAudioCategory];
} else {
[self.audioPlayer playWithPlaybackAudioCategory];
}
}
#pragma mark - Notifications
+ (OWSSound)defaultNotificationSound

@ -39,7 +39,7 @@ typedef NS_ENUM(NSInteger, AudioPlaybackState) {
- (void)playWithCurrentAudioCategory;
// respects silent switch, mixes with others
- (void)playWithAmbientAudioCategory;
- (void)playAsForegroundAlert;
// will ensure sound is audible, even if silent switch is enabled
- (void)playWithPlaybackAudioCategory;

@ -104,11 +104,12 @@ NS_ASSUME_NONNULL_BEGIN
[self play];
}
- (void)playWithAmbientAudioCategory
- (void)playAsForegroundAlert
{
OWSAssertIsOnMainThread();
[OWSAudioSession.shared startAmbientAudioActivity:self.audioActivity];
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
[self play];
}

Loading…
Cancel
Save