1

假设一个应用程序一次支持两个调用。第一个电话已接通,第二个电话打进来。一个得到“结束通话和接听电话”、“拒绝”、“保持通话和接听电话”按钮。

如果是“挂断接听电话”,则表示结束已接通的通话并接听新来电。在“拒绝”的情况下,意味着拒绝来电。

在这两种情况下,代表

- (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action

被触发。现在,如何知道要结束哪些呼叫,来电还是已接通的呼叫?CXEndCallAction没有说明“拒绝”或“结束已连接的呼叫”的原因

有没有人有办法解决吗?

4

3 回答 3

3

我发现有一个事务列表委托:

- (BOOL)provider:(CXProvider *)provider executeTransaction:(CXTransaction *)transaction

如果有一个事务会触发其他委托,例如CXSetHeldCallActionor ,实现这个委托将提供足够的信息CXEndCallAction。所以现在我可以决定触发什么动作,并在必要时绕过其他代表。

如果其他人在苦苦挣扎,这是我的代码:

- (BOOL)provider:(CXProvider *)provider executeTransaction:(CXTransaction *)transaction
{
NSLog(@"executeTransaction : %@", transaction.debugDescription);
BOOL callEnd = NO;
BOOL callHold= NO;
BOOL callAnswer = NO;

NSPredicate *filter = [NSPredicate predicateWithFormat:@"self isKindOfClass: %@", [CXEndCallAction class]];
NSArray *ends = [transaction.actions filteredArrayUsingPredicate:filter];
callEnd = [ends count] >= 1;

filter = [NSPredicate predicateWithFormat:@"self isKindOfClass: %@", [CXAnswerCallAction class]];
NSArray *answer = [transaction.actions filteredArrayUsingPredicate:filter];
callAnswer = [answer count] >= 1;

filter = [NSPredicate predicateWithFormat:@"self isKindOfClass: %@", [CXSetHeldCallAction class]];
NSArray *hold = [transaction.actions filteredArrayUsingPredicate:filter];
callHold = [hold count] >= 1;

if(callEnd && callAnswer)
{
    actionType = kCallKitEndAndAnswer;
    [[MyCallManager sharedManager] endPreviousCallAndAnswerNewCall:^(BOOL succeeded) {
        NSLog(@"end answered call: %@", succeeded ? @"yes" : @"No");
        CXEndCallAction *en = [ends firstObject];
        succeeded ? [en fulfill] : [en fail];

        CXAnswerCallAction *an= [answer firstObject];
        succeeded ? [an fulfill] : [an fail];

    }];
    return YES;
}
else if(callHold && callAnswer)
{
    actionType = kCallKitHoldAndAnswer;

    [[MyCallManager sharedManager] answerCall:^(BOOL succeeded) {
        NSLog(@"hold answered call: %@", succeeded ? @"yes" : @"No");
        CXSetHeldCallAction *ho = [hold firstObject];
        succeeded ? [ho fulfill] : [ho fail];

        CXAnswerCallAction *an= [answer firstObject];
        succeeded ? [an fulfill] : [an fail];
    }];
    return YES;
}
else if([hold count] == 2)
{
    [[MyCallManager sharedManager] swapCalls];
    usleep(25000);
    CXSetHeldCallAction * fi = [hold firstObject];
    CXSetHeldCallAction * la = [hold lastObject];
    [fi fulfill];
    [la fulfill];

    return YES;
}

return NO;
}
于 2016-12-02T13:54:12.380 回答
1

您需要访问 CXEndCallAction 的 callUUID 成员。

该事务在正确的对象上调用,因此您只需终止与传输的 UUID 匹配的调用。这意味着您必须将对 UUID 的支持添加到您自己的调用对象模型中。

于 2016-12-02T13:06:15.067 回答
0

您可以使用枚举和“isMemberOfClass”。

在 providerDelegate.h

 // Call Modes.
 typedef NS_ENUM(NSUInteger, CallMode) {
     kUnknownMode = 0,
     kEndAndAnswerMode = 1,
     kHoldAndAnswerMode = 2
};

在 providerDelegate.m

@property(nonatomic, assign) CallMode mode;

并添加以下代码以获取每笔交易。

- (BOOL)provider:(CXProvider *)provider executeTransaction:(CXTransaction *)transaction {

    NSLog(@"Provider execute transaction");

    BOOL callEnd = NO;
    BOOL callHold= NO;
    BOOL callAnswer = NO;

    NSPredicate *filter = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [CXEndCallAction class]];
    NSArray<CXEndCallAction *> *ends = [transaction.actions filteredArrayUsingPredicate:filter];
    callEnd = [ends count] >= 1;

    filter = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [CXAnswerCallAction class]];
    NSArray<CXAnswerCallAction *> *answers = [transaction.actions filteredArrayUsingPredicate:filter];
    callAnswer = [answers count] >= 1;

    filter = [NSPredicate predicateWithFormat:@"self isMemberOfClass: %@", [CXSetHeldCallAction class]];
    NSArray<CXSetHeldCallAction *> *holds = [transaction.actions filteredArrayUsingPredicate:filter];
    callHold = [holds count] >= 1;

    if(callEnd && callAnswer) {
        _mode = kEndAndAnswerMode;
    } else if(callHold && callAnswer) {
        _mode = kHoldAndAnswerMode;
    } else {
        _mode = kUnknownMode;
    }

    return NO;
}
于 2017-02-14T07:24:22.937 回答