Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure UI is updated on the main thread when denying mic permission and add support for sending DTMF #573

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 48 additions & 33 deletions ObjcVoiceQuickstart/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,39 +114,9 @@ - (IBAction)mainButtonPressed:(id)sender {

[self checkRecordPermission:^(BOOL permissionGranted) {
if (!permissionGranted) {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Voice Quick Start"
message:@"Microphone permission not granted."
preferredStyle:UIAlertControllerStyleAlert];

typeof(self) __weak weakSelf = self;
UIAlertAction *continueWithoutMic = [UIAlertAction actionWithTitle:@"Continue without microphone"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
typeof(self) __strong strongSelf = weakSelf;
[strongSelf performStartCallActionWithUUID:uuid handle:handle];
}];
[alertController addAction:continueWithoutMic];

NSDictionary *openURLOptions = @{UIApplicationOpenURLOptionUniversalLinksOnly: @NO};
UIAlertAction *goToSettings = [UIAlertAction actionWithTitle:@"Settings"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
options:openURLOptions
completionHandler:nil];
}];
[alertController addAction:goToSettings];

UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
typeof(self) __strong strongSelf = weakSelf;
[strongSelf toggleUIState:YES showCallControl:NO];
[strongSelf stopSpin];
}];
[alertController addAction:cancel];

[self presentViewController:alertController animated:YES completion:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[self showMicrophoneAccessRequestWithUUID:uuid handle:handle];
});
} else {
[self performStartCallActionWithUUID:uuid handle:handle];
}
Expand Down Expand Up @@ -180,6 +150,41 @@ - (void)checkRecordPermission:(void(^)(BOOL permissionGranted))completion {
}
}

- (void)showMicrophoneAccessRequestWithUUID:(NSUUID *)uuid handle:(NSString *)handle {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Voice Quick Start"
message:@"Microphone permission not granted."
preferredStyle:UIAlertControllerStyleAlert];

typeof(self) __weak weakSelf = self;
UIAlertAction *continueWithoutMic = [UIAlertAction actionWithTitle:@"Continue without microphone"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
typeof(self) __strong strongSelf = weakSelf;
[strongSelf performStartCallActionWithUUID:uuid handle:handle];
}];
[alertController addAction:continueWithoutMic];

NSDictionary *openURLOptions = @{UIApplicationOpenURLOptionUniversalLinksOnly: @NO};
UIAlertAction *goToSettings = [UIAlertAction actionWithTitle:@"Settings"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]
options:openURLOptions
completionHandler:nil];
}];
[alertController addAction:goToSettings];

UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action) {
typeof(self) __strong strongSelf = weakSelf;
[strongSelf toggleUIState:YES showCallControl:NO];
[strongSelf stopSpin];
}];
[alertController addAction:cancel];
[self presentViewController:alertController animated:YES completion:nil];
}

- (void)toggleUIState:(BOOL)isEnabled showCallControl:(BOOL)showCallControl {
self.placeCallButton.enabled = isEnabled;
if (showCallControl) {
Expand Down Expand Up @@ -690,6 +695,16 @@ - (void)provider:(CXProvider *)provider performSetMutedCallAction:(CXSetMutedCal
}
}

- (void)provider:(CXProvider *)provider performPlayDTMFCallAction:(CXPlayDTMFCallAction *)action {
TVOCall *call = self.activeCalls[action.callUUID.UUIDString];
if (call) {
[call sendDigits:action.digits];
[action fulfill];
} else {
[action fail];
}
}

#pragma mark - CallKit Actions
- (void)performStartCallActionWithUUID:(NSUUID *)uuid handle:(NSString *)handle {
if (uuid == nil || handle == nil) {
Expand Down
16 changes: 14 additions & 2 deletions SwiftVoiceQuickstart/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ class ViewController: UIViewController {
self?.performStartCallAction(uuid: uuid, handle: handle)
return
}

self?.showMicrophoneAccessRequest(uuid, handle)
DispatchQueue.main.async {
self?.showMicrophoneAccessRequest(uuid, handle)
}
}
}

Expand Down Expand Up @@ -716,6 +717,17 @@ extension ViewController: CXProviderDelegate {
}
}

func provider(_ provider: CXProvider, perform action: CXPlayDTMFCallAction) {
NSLog("provider:performPlayDTMFCallAction:")

if let call = activeCalls[action.callUUID.uuidString] {
call.sendDigits(action.digits)
action.fulfill()
} else {
action.fail()
}
}


// MARK: Call Kit Actions
func performStartCallAction(uuid: UUID, handle: String) {
Expand Down