refactor on getting microphone permission state to try to fix an issue

pull/1061/head
Ryan ZHAO 3 months ago
parent 3a91bc52e1
commit 403ca8c10c

@ -192,6 +192,7 @@
9473386E2BDF5F3E00B9E169 /* InfoPlist.xcstrings in Resources */ = {isa = PBXBuildFile; fileRef = 9473386D2BDF5F3E00B9E169 /* InfoPlist.xcstrings */; };
947AD6902C8968FF000B2730 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 947AD68F2C8968FF000B2730 /* Constants.swift */; };
94B3DC172AF8592200C88531 /* QuoteView_SwiftUI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94B3DC162AF8592200C88531 /* QuoteView_SwiftUI.swift */; };
94C58AC92D2E037200609195 /* Permissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C58AC82D2E036E00609195 /* Permissions.swift */; };
94C5DCB02BE88170003AA8C5 /* BezierPathView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C5DCAF2BE88170003AA8C5 /* BezierPathView.swift */; };
94E9BC0D2C7BFBDA006984EA /* Localization+Style.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94E9BC0C2C7BFBDA006984EA /* Localization+Style.swift */; };
A11CD70D17FA230600A2D1B1 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A11CD70C17FA230600A2D1B1 /* QuartzCore.framework */; };
@ -1398,6 +1399,7 @@
9473386D2BDF5F3E00B9E169 /* InfoPlist.xcstrings */ = {isa = PBXFileReference; lastKnownFileType = text.json.xcstrings; path = InfoPlist.xcstrings; sourceTree = "<group>"; };
947AD68F2C8968FF000B2730 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
94B3DC162AF8592200C88531 /* QuoteView_SwiftUI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuoteView_SwiftUI.swift; sourceTree = "<group>"; };
94C58AC82D2E036E00609195 /* Permissions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Permissions.swift; sourceTree = "<group>"; };
94C5DCAF2BE88170003AA8C5 /* BezierPathView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BezierPathView.swift; sourceTree = "<group>"; };
94E9BC0C2C7BFBDA006984EA /* Localization+Style.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Localization+Style.swift"; sourceTree = "<group>"; };
A11CD70C17FA230600A2D1B1 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
@ -3625,6 +3627,7 @@
FD09796527F6B0A800936362 /* Utilities */ = {
isa = PBXGroup;
children = (
94C58AC82D2E036E00609195 /* Permissions.swift */,
FD6A39422C2AD81600762359 /* BackgroundTaskManager.swift */,
FDFBB74A2A1EFF4900CA7350 /* Bencode.swift */,
FD6A39162C2A99A000762359 /* BencodeDecoder.swift */,
@ -5824,6 +5827,7 @@
C3C2AC2E2553CBEB00C340D1 /* String+Trimming.swift in Sources */,
FD17D7C727F5207C00122BE0 /* DatabaseMigrator+Utilities.swift in Sources */,
FD848B9328420164000E298B /* UnicodeScalar+Utilities.swift in Sources */,
94C58AC92D2E037200609195 /* Permissions.swift in Sources */,
FD09796B27F6C67500936362 /* Failable.swift in Sources */,
FD7115FA28C8153400B47552 /* UIBarButtonItem+Combine.swift in Sources */,
FD705A92278D051200F16121 /* ReusableView.swift in Sources */,

@ -1,5 +1,5 @@
{
"originHash" : "c57241b796915b0642f9c260463b2d6fd7d5198beafde785c590f3a7d80d31f5",
"originHash" : "4c95b434de06c87c75c3ef96fa055ec67e885a4a4ad78caafd7925b131995b07",
"pins" : [
{
"identity" : "cocoalumberjack",

@ -121,7 +121,7 @@ extension ConversationVC:
let threadId: String = self.viewModel.threadData.threadId
guard
AVAudioSession.sharedInstance().recordPermission == .granted,
Permissions.hasMicrophonePermission,
self.viewModel.threadData.threadVariant == .contact,
Singleton.callManager.currentCall == nil,
let call: SessionCall = Storage.shared.read({ [dependencies = viewModel.dependencies] db in
@ -2487,7 +2487,7 @@ extension ConversationVC:
// Keep screen on
UIApplication.shared.isIdleTimerDisabled = false
guard AVAudioSession.sharedInstance().recordPermission == .granted else { return }
guard Permissions.hasMicrophonePermission else { return }
// Cancel any current audio playback
self.viewModel.stopAudio()

File diff suppressed because one or more lines are too long

@ -8,7 +8,7 @@ import SessionUIKit
import SessionUtilitiesKit
import SessionMessagingKit
public enum Permissions {
extension Permissions {
@discardableResult public static func requestCameraPermissionIfNeeded(
presentingViewController: UIViewController? = nil,
onAuthorized: (() -> Void)? = nil

@ -81,8 +81,7 @@ extension MessageReceiver {
return
}
let hasMicrophonePermission: Bool = (AVAudioSession.sharedInstance().recordPermission == .granted)
guard db[.areCallsEnabled] && hasMicrophonePermission else {
guard db[.areCallsEnabled] && Permissions.hasMicrophonePermission else {
let state: CallMessage.MessageInfo.State = (db[.areCallsEnabled] ? .permissionDeniedMicrophone : .permissionDenied)
if let interaction: Interaction = try MessageReceiver.insertCallInfoMessage(db, for: message, state: state, using: dependencies) {

@ -176,16 +176,17 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol {
let senderName: String = Profile.displayName(db, id: interaction.authorId, threadVariant: thread.variant)
if messageInfo.state == .permissionDenied {
notificationContent.body = "callsYouMissedCallPermissions"
.put(key: "name", value: senderName)
.localizedDeformatted()
}
else if messageInfo.state == .permissionDeniedMicrophone {
notificationContent.body = String(
format: "callsMissedCallFrom".localized(),
senderName
)
switch messageInfo.state {
case .permissionDenied:
notificationContent.body = "callsYouMissedCallPermissions"
.put(key: "name", value: senderName)
.localizedDeformatted()
case .permissionDeniedMicrophone:
notificationContent.body = "callsMissedCallFrom"
.put(key: "name", value: senderName)
.localizedDeformatted()
default:
break
}
addNotifcationRequest(

@ -154,8 +154,7 @@ public final class NotificationServiceExtension: UNNotificationServiceExtension
throw NotificationError.ignorableMessage
}
let hasMicrophonePermission: Bool = (AVAudioSession.sharedInstance().recordPermission == .granted)
switch ((db[.areCallsEnabled] && hasMicrophonePermission), isCallOngoing) {
switch ((db[.areCallsEnabled] && Permissions.hasMicrophonePermission), isCallOngoing) {
case (false, _):
if
let sender: String = callMessage.sender,

@ -0,0 +1,13 @@
// Copyright © 2025 Rangeproof Pty Ltd. All rights reserved.
import AVFAudio
public enum Permissions {
public static var hasMicrophonePermission: Bool {
if #available(iOSApplicationExtension 17.0, *) {
AVAudioApplication.shared.recordPermission == .granted
} else {
AVAudioSession.sharedInstance().recordPermission == .granted
}
}
}
Loading…
Cancel
Save