Respect silent-switch pre-CallKit

8 Cases considered:

(Silent Switch toggled vs. Silent Switch not-toggled)
x (App in Foreground vs. App in Background)
x (CallKit vs. NonCallKit)

CallKit already does the "right thing"

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent e3a5451080
commit a89bde933d

@ -22,6 +22,7 @@
#import "UIFont+OWS.h"
#import "UIUtil.h"
#import "UIView+OWS.h"
#import <JSQSystemSoundPlayer.h>
#import <SignalServiceKit/Contact.h>
#import <SignalServiceKit/Cryptography.h>
#import <SignalServiceKit/NSData+Base64.h>

@ -94,7 +94,8 @@
UILocalNotification *notification = [UILocalNotification new];
notification.category = PushManagerCategoriesIncomingCall;
notification.soundName = @"r.caf";
// Rather than using notification sounds, we control the ringtone and repeat vibrations with the CallAudioManager.
// notification.soundName = @"r.caf";
NSString *localCallId = call.localId.UUIDString;
notification.userInfo = @{ PushManagerUserInfoKeysLocalCallId : localCallId };

@ -11,6 +11,11 @@ import PromiseKit
private let TAG = "[CallAudioService]"
private var vibrateTimer: Timer?
private let audioManager = AppAudioManager.sharedInstance()
private let soundPlayer = JSQSystemSoundPlayer.shared()!
enum SoundFilenames: String {
case incomingRing = "r"
}
// Mark: Vibration config
private let vibrateRepeatDuration = 1.6
@ -59,9 +64,9 @@ import PromiseKit
private func handleLocalRinging() {
Logger.debug("\(TAG) \(#function)")
audioManager.setAudioEnabled(true)
audioManager.handleInboundRing()
vibrateTimer = Timer.scheduledTimer(timeInterval: vibrateRepeatDuration, target: self, selector: #selector(vibrate), userInfo: nil, repeats: true)
vibrateTimer = Timer.scheduledTimer(timeInterval: vibrateRepeatDuration, target: self, selector: #selector(ringVibration), userInfo: nil, repeats: true)
soundPlayer.playSound(withFilename: SoundFilenames.incomingRing.rawValue, fileExtension: kJSQSystemSoundTypeCAF)
}
private func handleConnected() {
@ -96,18 +101,18 @@ import PromiseKit
// MARK: Helpers
private func stopRinging() {
// Disables external speaker used for ringing, unless user enables speakerphone.
audioManager.setDefaultAudioProfile()
audioManager.cancelAllAudio()
vibrateTimer?.invalidate()
vibrateTimer = nil
soundPlayer.stopSound(withFilename: SoundFilenames.incomingRing.rawValue)
}
public func vibrate() {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
public func ringVibration() {
// Since a call notification is more urgent than a message notifaction, we
// vibrate twice, like a pulse, to differentiate from a normal notification vibration.
soundPlayer.playVibrateSound()
DispatchQueue.default.asyncAfter(deadline: DispatchTime.now() + pulseDuration) {
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
self.soundPlayer.playVibrateSound()
}
}
}

Loading…
Cancel
Save