PJSIP撥打電話庫:VialerSIPLib藤乙,這個應(yīng)該是Github上能找到上手門檻比較低并且比較強(qiáng)大的PJSIP庫了燕差。
0絮爷、運(yùn)行GitHub上VialerSIPLib的Demo
0.1、clone 或 下載zip埋哟,然后pod install
0.2笆豁、修改Keys.swift.example
文件名為Keys.swift
,并為Keys.swift
中的屬性賦值
可能會出現(xiàn)錯誤
PJSUA_IP_CHANGE_OP_COMPLETED 未定義
赤赊,將VSLEndpoint.m
中這段代碼注釋了即可
// case PJSUA_IP_CHANGE_OP_COMPLETED: {
// VSLLogDebug(@"The ip change process has completed, status: %s", statusmsg);
// [VSLEndpoint sharedEndpoint].ipChangeInProgress = NO;
// break;
// }
1闯狱、集成
pod 'VialerSIPLib', "3.7.3"
1.1、同時添加一下代碼
post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'PJ_AUTOCONF=1'
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '10.0'
end
end
end
1.2抛计、如果Podfile
文件中使用了use_frameworks!
哄孤,需添加一下代碼。否則會報“The ‘Pods-XXX‘ target has transitive dependencies that include statically linked binaries”
pre_install do |installer|
# workaround for https://github.com/CocoaPods/CocoaPods/issues/3289
Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_static_framework_transitive_dependencies) {}
end
2吹截、使用
2.1瘦陈、配置VialerSIPLib
- (void)configureVialerSIPLib
{
VSLEndpointConfiguration *endpointConfiguration = [[VSLEndpointConfiguration alloc] init];
VSLTransportConfiguration *updTransportConfiguration = [VSLTransportConfiguration configurationWithTransportType:VSLTransportTypeUDP];
endpointConfiguration.transportConfigurations = @[updTransportConfiguration];
NSError *error;
BOOL success = [[VialerSIPLib sharedInstance] configureLibraryWithEndPointConfiguration:endpointConfiguration error:&error];
if (!success || error) {
NSLog(@"Failed to startup VialerSIPLib: %@", error);
}
}
2.2、注冊SIP賬號
- (void)addSipUser
{
FGSipUserModel *model = [[FGSipUserModel alloc] init];
model.sipAccount = @"";
model.sipPassword = @"";
model.sipDomain = @"";
model.sipProxy = @"xxx.xxx.xxx:5060";
NSError *error;
self.account = [[VialerSIPLib sharedInstance] createAccountWithSipUser:model error:&error];
if (error) {
NSLog(@"Failed to create Account: %@", error);
} else {
NSLog(@"Succeed to create Account");
}
}
1.上面的
FGSipUserModel
類需實(shí)現(xiàn)SIPEnabledUser
協(xié)議.
2.這里的self.account
這樣定義@property (nonatomic, strong) VSLAccount *account;
波俄,最好是作為AppDelegate
的屬性晨逝。
// FGSipUserModel.h
#import <Foundation/Foundation.h>
#import <VialerSIPLib/VialerSIPLib.h>
@interface FGSipUserModel : NSObject<SIPEnabledUser>
@property (nonatomic, readwrite) NSString *sipAccount;
@property (nonatomic, readwrite) NSString *sipPassword;
@property (nonatomic, readwrite) NSString *sipDomain;
@property (nonatomic, readwrite) NSString *sipProxy;
@end
// FGSipUserModel.m
#import "FGSipUserModel.h"
@implementation FGSipUserModel
@synthesize sipAccount = _sipAccount;
@synthesize sipPassword = _sipPassword;
@synthesize sipDomain = _sipDomain;
@synthesize sipProxy = _sipProxy;
@end
2.3、撥打電話
[[VialerSIPLib sharedInstance].callManager startCallToNumber:@"8007"
forAccount:self.account
completion:^(VSLCall * _Nullable call, NSError * _Nullable error) {
if (error) {
NSLog(@"Call error:%@", error);
}
}];
文章還未完成懦铺,敬請期待...