-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release RongCloud CallKit SDK 2.8.31
- Loading branch information
Showing
57 changed files
with
3,294 additions
and
2,293 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
241 changes: 183 additions & 58 deletions
241
ios-rongcallkit/RongCallKit/Controller/RCCallBaseViewController.m
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// RCCXCall.h | ||
// RongCallKit | ||
// | ||
// Created by LiFei on 2018/1/17. | ||
// Copyright © 2018年 Rong Cloud. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/*! | ||
融云适配苹果 CallKit 核心类 | ||
*/ | ||
@interface RCCXCall : NSObject | ||
|
||
/** | ||
获取 RCCXCall 单例 | ||
@return RCCXCall 单例 | ||
*/ | ||
+ (instancetype)sharedInstance; | ||
|
||
/*! | ||
通知苹果 Callkit 开始呼出电话 | ||
@param userId 呼叫用户 id,如果是多人通话则传多个用户 id,以:::分隔 | ||
*/ | ||
- (void)startCall:(NSString *)userId; | ||
|
||
/*! | ||
通知苹果 Callkit 呼出电话已连接 | ||
*/ | ||
- (void)reportOutgoingCallConnected; | ||
|
||
/** | ||
通知苹果 Callkit 来电 | ||
@param inviterId 来电人用户 id | ||
@param userIdList 被邀请者的 userId 列表。nil 表示单人通话 | ||
@param isVideo 是否视频通话。YES: video NO: audio | ||
*/ | ||
- (void)reportIncomingCallWithInviter:(NSString *)inviterId | ||
userIdList:(NSArray <NSString *> *)userIdList | ||
isVideo:(BOOL)isVideo; | ||
|
||
/*! | ||
挂断苹果 Callkit 通话 | ||
*/ | ||
- (void)endCXCall; | ||
|
||
/** | ||
当系统来电接通时,如果没有激活苹果 Callkit 通话,则挂断 VOIP | ||
@param UUID 系统来电 UUID | ||
*/ | ||
- (void)hangupIfNeedWithUUID:(NSString *)UUID; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
// | ||
// RCCXCall.m | ||
// RongCallKit | ||
// | ||
// Created by LiFei on 2018/1/17. | ||
// Copyright © 2018年 Rong Cloud. All rights reserved. | ||
// | ||
|
||
#import "RCCXCall.h" | ||
#import "RCCall.h" | ||
#import "RCUserInfoCacheManager.h" | ||
#import <CallKit/CallKit.h> | ||
#import <AVFoundation/AVFoundation.h> | ||
#import "RCCallKitUtility.h" | ||
|
||
#define RCCXCallLocalizedName @"RongCloud" | ||
|
||
@interface RCCXCall() <CXProviderDelegate> | ||
@property(nonatomic, strong) CXProvider *provider; | ||
@property(nonatomic, strong) NSUUID *currentUUID; | ||
@property(nonatomic, strong) CXCallController *controller; | ||
@end | ||
|
||
@implementation RCCXCall | ||
|
||
+ (instancetype)sharedInstance { | ||
static RCCXCall *pCall; | ||
static dispatch_once_t onceToken; | ||
if (RC_IOS_SYSTEM_VERSION_LESS_THAN(@"10.0")) { | ||
return nil; | ||
} | ||
dispatch_once(&onceToken, ^{ | ||
if (pCall == nil) { | ||
pCall = [[RCCXCall alloc] init]; | ||
} | ||
}); | ||
return pCall; | ||
} | ||
|
||
- (void)startCall:(NSString *)userId { | ||
if (userId.length > 0) { | ||
NSUUID *uuid = [NSUUID UUID]; | ||
self.currentUUID = uuid; | ||
CXHandle *handle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:[userId copy]]; | ||
CXStartCallAction *startAction = [[CXStartCallAction alloc] initWithCallUUID:uuid handle:handle]; | ||
NSArray *array = [userId componentsSeparatedByString:@":::"]; | ||
if (array.count == 1) { | ||
startAction.contactIdentifier = [[RCUserInfoCacheManager sharedManager] getUserInfo:userId].name; | ||
} else { | ||
NSString *str = @""; | ||
for (NSString *uId in array) { | ||
NSString *name = [[RCUserInfoCacheManager sharedManager] getUserInfo:uId].name; | ||
if (name.length > 0) { | ||
str = [str stringByAppendingFormat:@"%@、", name]; | ||
} | ||
} | ||
if (str.length > 0) { | ||
str = [str substringToIndex:str.length - 1]; | ||
} | ||
startAction.contactIdentifier = str; | ||
} | ||
CXTransaction *transaction = [[CXTransaction alloc] init]; | ||
[transaction addAction:startAction]; | ||
[self.controller requestTransaction:transaction completion:^(NSError * _Nullable error) { | ||
}]; | ||
[self.provider reportOutgoingCallWithUUID:uuid startedConnectingAtDate:nil]; | ||
} | ||
} | ||
|
||
- (void)reportOutgoingCallConnected { | ||
[self.provider reportOutgoingCallWithUUID:self.currentUUID connectedAtDate:nil]; | ||
} | ||
|
||
- (void)reportIncomingCallWithInviter:(NSString *)inviterId | ||
userIdList:(NSArray<NSString *> *)userIdList | ||
isVideo:(BOOL)isVideo { | ||
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil]; | ||
NSUUID *uuid = [[NSUUID alloc] init]; | ||
self.currentUUID = uuid; | ||
CXCallUpdate *update = [[CXCallUpdate alloc] init]; | ||
NSString *localizedCallerName = [[RCUserInfoCacheManager sharedManager] getUserInfo:inviterId].name; | ||
NSString *handleValue = inviterId; | ||
for (NSString *userId in userIdList) { | ||
if ([userId isEqualToString:inviterId]) { | ||
break; | ||
} | ||
NSString *name = [[RCUserInfoCacheManager sharedManager] getUserInfo:userId].name; | ||
if (name.length > 0) { | ||
localizedCallerName = [localizedCallerName stringByAppendingFormat:@"、%@", name]; | ||
} | ||
handleValue = [handleValue stringByAppendingFormat:@":::%@", userId]; | ||
} | ||
update.localizedCallerName = localizedCallerName; | ||
CXHandle *handle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:handleValue]; | ||
update.remoteHandle = handle; | ||
if (isVideo) { | ||
update.hasVideo = YES; | ||
} | ||
[self.provider reportNewIncomingCallWithUUID:uuid | ||
update:update | ||
completion:^(NSError * _Nullable error) { | ||
if (error == nil) { | ||
} | ||
}]; | ||
} | ||
|
||
- (void)endCXCall { | ||
if (self.currentUUID) { | ||
CXEndCallAction *endAction = [[CXEndCallAction alloc] initWithCallUUID:self.currentUUID]; | ||
CXTransaction *transaction = [[CXTransaction alloc] init]; | ||
[transaction addAction:endAction]; | ||
[self.controller requestTransaction:transaction completion:^(NSError * _Nullable error) { | ||
self.currentUUID = nil; | ||
}]; | ||
} | ||
} | ||
|
||
- (void)hangupIfNeedWithUUID:(NSString *)UUID { | ||
if (UUID.length == 0) { | ||
return; | ||
} | ||
if (![UUID isEqualToString:self.currentUUID.UUIDString]) { | ||
[[RCCall sharedRCCall].currentCallSession hangup]; | ||
} | ||
} | ||
|
||
- (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action { | ||
if ([self.currentUUID.UUIDString isEqualToString:action.callUUID.UUIDString]) { | ||
[[RCCall sharedRCCall].currentCallSession accept:[RCCall sharedRCCall].currentCallSession.mediaType]; | ||
} | ||
[action fulfill]; | ||
} | ||
|
||
- (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action { | ||
if ([self.currentUUID.UUIDString isEqualToString:action.callUUID.UUIDString]) { | ||
[[RCCall sharedRCCall].currentCallSession hangup]; | ||
self.currentUUID = nil; | ||
} | ||
[action fulfill]; | ||
} | ||
|
||
- (void)provider:(CXProvider *)provider performStartCallAction:(CXStartCallAction *)action { | ||
//startCall的时候设置action的contactIdentifier并不会更新通话记录中的名字,这段代码是为了更新通话记录 | ||
CXCallUpdate *update = [[CXCallUpdate alloc] init]; | ||
update.remoteHandle = action.handle; | ||
update.localizedCallerName = action.contactIdentifier; | ||
[self.provider reportCallWithUUID:action.callUUID updated:update]; | ||
[action fulfill]; | ||
} | ||
|
||
- (void)providerDidReset:(CXProvider *)provider { | ||
//info.plist里面没有打开后台VoIP模式的情况下,在startCall之后会走这个回调,导致呼出的电话被hangup | ||
// if (self.currentUUID) { | ||
// self.currentUUID = nil; | ||
// if ([RCCall sharedRCCall].currentCallSession) { | ||
// [[RCCall sharedRCCall].currentCallSession hangup]; | ||
// } | ||
// } | ||
} | ||
|
||
- (CXProvider *)provider { | ||
if (!_provider) { | ||
NSString *name = [RCCall sharedRCCall].appLocalizedName; | ||
if (name.length == 0) { | ||
name = RCCXCallLocalizedName; | ||
} | ||
CXProviderConfiguration *config = [[CXProviderConfiguration alloc] initWithLocalizedName:name]; | ||
config.supportedHandleTypes = [NSSet setWithObject:@(CXHandleTypeGeneric)]; | ||
config.maximumCallGroups = 1; | ||
config.maximumCallsPerCallGroup = 1; | ||
|
||
UIImage *img = [RCCallKitUtility imageFromVoIPBundle:@"voip/callkit_app_icon.png"]; | ||
NSData *data = UIImagePNGRepresentation(img); | ||
config.iconTemplateImageData = data; | ||
_provider = [[CXProvider alloc] initWithConfiguration:config]; | ||
[_provider setDelegate:self queue:nil]; | ||
} | ||
return _provider; | ||
} | ||
|
||
- (CXCallController *)controller { | ||
if (!_controller) { | ||
_controller = [[CXCallController alloc] init]; | ||
} | ||
return _controller; | ||
} | ||
|
||
@end |
Oops, something went wrong.