[英]INStartVideoCallIntent from call history and CallKit video button
[英]Display video button in CallKit incoming call screen when call is video
我正在使用以下代碼接收視頻通話。 我的應用程序具有音頻和視頻通話功能,我正在使用 linphone + CallKit。
- (void)config {
CXProviderConfiguration *config = [[CXProviderConfiguration alloc]
initWithLocalizedName:[NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleName"]];
config.ringtoneSound = @"notes_of_the_optimistic.caf";
config.supportsVideo = TRUE;
config.iconTemplateImageData = UIImagePNGRepresentation([UIImage imageNamed:@"callkit_logo"]);
NSArray *ar = @[ [NSNumber numberWithInt:(int)CXHandleTypeGeneric] ];
NSSet *handleTypes = [[NSSet alloc] initWithArray:ar];
[config setSupportedHandleTypes:handleTypes];
[config setMaximumCallGroups:2];
[config setMaximumCallsPerCallGroup:1];
self.provider = [[CXProvider alloc] initWithConfiguration:config];
[self.provider setDelegate:self queue:dispatch_get_main_queue()];
}
- (void)reportIncomingCall:(LinphoneCall *) call withUUID:(NSUUID *)uuid handle:(NSString *)handle video:(BOOL)video
{
CXCallUpdate *update = [[CXCallUpdate alloc] init];
update.remoteHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handle];
update.supportsDTMF = TRUE;
update.supportsHolding = TRUE;
update.supportsGrouping = TRUE;
update.supportsUngrouping = TRUE;
update.hasVideo = video;
linphone_call_ref(call);
// Report incoming call to system
LOGD(@"CallKit: report new incoming call");
[self.provider reportNewIncomingCallWithUUID:uuid
update:update
completion:^(NSError *error) {
if (error) {
LOGE(@"CallKit: cannot complete incoming call from [%@] caused by [%@]",handle,[error localizedDescription]);
if ( [error code] == CXErrorCodeIncomingCallErrorFilteredByDoNotDisturb
|| [error code] == CXErrorCodeIncomingCallErrorFilteredByBlockList) {
linphone_call_decline(call,LinphoneReasonBusy); /*to give a chance for other devices to answer*/
} else {
linphone_call_decline(call,LinphoneReasonUnknown);
}
}
linphone_call_unref(call);
}];
}
請參閱隨附的來電視頻通話 UI 屏幕截圖。 它為音頻和視頻通話顯示相同的 UI(按鈕)。 當通話是視頻時,我想顯示一個視頻通話按鈕。 可以使用 CallKit 嗎? 如果可能,需要做出哪些改變? 提前致謝。
不,很遺憾,無法自定義 CallKit 來電 UI。 這就是為什么 WhatsApp 等應用程序使用推送通知來通知視頻通話,而不是依賴 CallKit 的原因。
請查看此演示。 CallKit 有一個屬性supportsVideo
的CXProviderConfiguration
和一個屬性hasVideo
的CXHandle
。 它對我來說很好。 檢查下面的演示鏈接。
https://websitebeaver.com/callkit-swift-tutorial-super-easy
func setupVdeoCall() {
let config = CXProviderConfiguration(localizedName: "My App")
config.iconTemplateImageData = UIImagePNGRepresentation(UIImage(named: "pizza")!)
config.ringtoneSound = "ringtone.caf"
config.includesCallsInRecents = false;
config.supportsVideo = true;
let provider = CXProvider(configuration: config)
provider.setDelegate(self, queue: nil)
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: "Pete Za")
update.hasVideo = true
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
}
所以只需修改ProviderDelegate.swift
文件,如下所示。
static var providerConfiguration: CXProviderConfiguration {
let localizedName = NSLocalizedString("CallKitDemo", comment: "Name of application")
let providerConfiguration = CXProviderConfiguration(localizedName: localizedName)
providerConfiguration.supportsVideo = true. //For Video Call Enable
providerConfiguration.includesCallsInRecents = false; //Show hide from phone recent call history
providerConfiguration.maximumCallsPerCallGroup = 1
providerConfiguration.supportedHandleTypes = [.phoneNumber]
providerConfiguration.iconTemplateImageData = #imageLiteral(resourceName: "IconMask").pngData()
providerConfiguration.ringtoneSound = "Ringtone.caf"
return providerConfiguration
}
和 reportIncomingCall()
func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)? = nil) {
// Construct a CXCallUpdate describing the incoming call, including the caller.
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .phoneNumber, value: handle)
update.hasVideo = hasVideo //For Video Call available or not
// pre-heat the AVAudioSession
//OTAudioDeviceManager.setAudioDevice(OTDefaultAudioDevice.sharedInstance())
// Report the incoming call to the system
provider.reportNewIncomingCall(with: uuid, update: update) { error in
/*
Only add incoming call to the app's list of calls if the call was allowed (i.e. there was no error)
since calls may be "denied" for various legitimate reasons. See CXErrorCodeIncomingCallError.
*/
if error == nil {
let call = SpeakerboxCall(uuid: uuid)
call.handle = handle
self.callManager.addCall(call)
}
completion?(error as NSError?)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.