美文网首页
iOS集成使用VialerSIPLib

iOS集成使用VialerSIPLib

作者: 落寞绅士 | 来源:发表于2023-02-08 18:03 被阅读0次

    PJSIP拨打电话库:VialerSIPLib,这个应该是Github上能找到上手门槛比较低并且比较强大的PJSIP库了。

    0、运行GitHub上VialerSIPLib的Demo

    0.1、clone 或 下载zip,然后pod install
    0.2、修改Keys.swift.example文件名为Keys.swift,并为Keys.swift中的属性赋值

    可能会出现错误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类需实现SIPEnabledUser协议.
    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);
            }
    }];
    

    文章还未完成,敬请期待...

    相关文章

      网友评论

          本文标题:iOS集成使用VialerSIPLib

          本文链接:https://www.haomeiwen.com/subject/tjwqkdtx.html