Vibrate when playing sound as alert

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

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

@ -48,9 +48,6 @@ typedef NS_ENUM(NSUInteger, OWSSound) {
+ (nullable NSString *)filenameForSound:(OWSSound)sound; + (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 #pragma mark - Notifications
+ (NSArray<NSNumber *> *)allNotificationSounds; + (NSArray<NSNumber *> *)allNotificationSounds;

@ -17,8 +17,6 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob
@property (nonatomic, readonly) YapDatabaseConnection *dbConnection; @property (nonatomic, readonly) YapDatabaseConnection *dbConnection;
@property (nonatomic, nullable) OWSAudioPlayer *audioPlayer;
@end @end
#pragma mark - #pragma mark -
@ -209,27 +207,6 @@ NSString *const kOWSSoundsStorageGlobalNotificationKey = @"kOWSSoundsStorageGlob
return url; 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 #pragma mark - Notifications
+ (OWSSound)defaultNotificationSound + (OWSSound)defaultNotificationSound

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

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

Loading…
Cancel
Save