2016-10-04 89 views
2

我正在嘗試將CallKit集成到我的Voip應用程序中。我提到了Apple WWDC的SpeakerBox示例代碼。我創建了一個ProviderDelegate類,我可以在調用reportNewIncomingCall方法後看到來電UI。CXProviderDelegate方法不會觸發

但是當我點擊「答案」/「結束」按鈕時,相應的提供者代表未被解僱。這裏有什麼可能是錯的?

請注意,當我實例化CallProviderDelegate時,會調用「providerDidBegin」。

@implementation CallProviderDelegate 

- (instancetype)init 
{ 
    self = [super init]; 
    if (self) { 
     _providerConfiguration = [self getProviderConfiguration]; 
     _provider = [[CXProvider alloc] initWithConfiguration:_providerConfiguration]; 
     [_provider setDelegate:self queue:nil]; 
    } 
    return self; 
} 

- (void)providerDidBegin:(CXProvider *)provider { 
    // this is getting called 
} 

- (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action { 
    // this is not getting called when the Answer button is pressed 
} 

- (void)reportNewIncomingCallWithUUID:(nonnull NSUUID *)UUID handle:(nonnull NSString *)handle 
          completion:(nullable void (^)(NSError *_Nullable error))completion { 

    CXCallUpdate *update = [[CXCallUpdate alloc] init]; 
    update.remoteHandle = [[CXHandle alloc] initWithType:CXHandleTypePhoneNumber value:handle]; 
    update.hasVideo = NO; 

    [_provider reportNewIncomingCallWithUUID:UUID update:update completion:^(NSError * _Nullable error) { 
     completion(error); 
    }]; 
} 

在主叫類:

CallProviderDelegate *providerDelegate = [[CallProviderDelegate alloc] init]; 
[providerDelegate reportNewIncomingCallWithUUID:[NSUUID UUID] handle:@"Raj" completion:^(NSError * _Nullable error) { 
      // 
}]; 

回答

2

在你的「來電顯示」類,即在其中實例化CallProviderDelegate類,並將其分配給providerDelegate變量的代碼,你存儲providerDelegate對象引用在一個實例變量或屬性?如果僅將其分配給臨時局部變量,則在調用方法結束執行後,將取消分配對象,並且如果解除分配對象,則不會傳遞進一步的CXProvider委託消息。

我會檢查你的CallProviderDelegate對象是不是被意外解除分配。

+0

是的,我犯了這個確切的錯誤,稍後修復它。忘記更新線程。感謝您花時間回答斯圖爾特。 – Rajavelu

+0

@Rajavelu:你可以讓我知道你怎麼能把APP的CallKit UI前端? –

+0

@SaurabhPrajapati您需要從提供者委託中調用'reportNewIncomingCall'方法。 – Rajavelu