Skip to content

Commit 6381877

Browse files
authored
Merge pull request #265 from AndreiMisiukevich/maco
Macos: Fix mic permission access
2 parents 037adb3 + ea9368e commit 6381877

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ However, you'll need to:
269269
2. include Hardened Runtime entitlements (this is required for App Store distributed MacOS apps):
270270

271271
```xml
272-
<key>com.apple.security.audio-input</key>
272+
<key>com.apple.security.device.audio-input</key>
273273
<true/>
274274
275275
<!--Optionally for bluetooth support/permissions-->

macos/Classes/JsInterop/Device/TVDevice.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ public class TVDevice: JSObject, TVDeviceDelegate, JSMessageHandlerDelegate {
208208
case .registering:
209209
onDeviceRegistering()
210210
break
211-
default:
212-
print("Unhandled event: \(event)")
213211
}
214212
}
215213
}

macos/Classes/TwilioVoicePlugin.swift

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Cocoa
22
import FlutterMacOS
3-
import WebKit
3+
@preconcurrency import WebKit
44
import SwiftUI
55
import UserNotifications
66
import AVFoundation
@@ -663,7 +663,7 @@ public class TwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHandler, T
663663

664664
// TODO: toggle bluetooth
665665
// toggleAudioRoute(toSpeaker: speakerIsOn)
666-
guard let eventSink = eventSink else {
666+
guard eventSink != nil else {
667667
return
668668
}
669669
logEvent(description: bluetoothOn ? "Bluetooth On" : "Bluetooth Off")
@@ -1142,9 +1142,9 @@ public class TwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHandler, T
11421142
if let category = NotificationCategory(rawValue: notification.request.content.categoryIdentifier) {
11431143
switch category {
11441144
case .incoming:
1145-
completionHandler([.alert, .banner, .sound])
1145+
completionHandler([.banner, .sound])
11461146
case .missed:
1147-
completionHandler([.alert, .banner, .sound])
1147+
completionHandler([.banner, .sound])
11481148
// default:
11491149
// completionHandler([])
11501150
}
@@ -1436,8 +1436,34 @@ public class TwilioVoicePlugin: NSObject, FlutterPlugin, FlutterStreamHandler, T
14361436
}
14371437

14381438
@available(macOS 12.0, *)
1439-
public func webView(_ webView: WKWebView, decideMediaCapturePermissionsFor origin: WKSecurityOrigin, initiatedBy frame: WKFrameInfo, type: WKMediaCaptureType) async -> WKPermissionDecision {
1440-
WKPermissionDecision.grant
1439+
public func webView(_ webView: WKWebView, requestMediaCapturePermissionFor origin: WKSecurityOrigin, initiatedByFrame frame: WKFrameInfo, type: WKMediaCaptureType, decisionHandler: @escaping @MainActor (WKPermissionDecision) -> Void) {
1440+
switch type {
1441+
case .microphone:
1442+
// For microphone access, we'll check the current permission status
1443+
switch AVCaptureDevice.authorizationStatus(for: .audio) {
1444+
case .authorized:
1445+
decisionHandler(.grant)
1446+
case .notDetermined:
1447+
// Request permission and handle the result
1448+
AVCaptureDevice.requestAccess(for: .audio) { granted in
1449+
Task { @MainActor in
1450+
decisionHandler(granted ? .grant : .deny)
1451+
}
1452+
}
1453+
case .denied, .restricted:
1454+
decisionHandler(.deny)
1455+
@unknown default:
1456+
decisionHandler(.deny)
1457+
}
1458+
case .camera:
1459+
// We don't need camera access for Twilio Voice
1460+
decisionHandler(.deny)
1461+
case .cameraAndMicrophone:
1462+
// We don't need camera and microphone access for Twilio Voice
1463+
decisionHandler(.deny)
1464+
@unknown default:
1465+
decisionHandler(.deny)
1466+
}
14411467
}
14421468
}
14431469

0 commit comments

Comments
 (0)