一嫁艇、SIP賬號登錄
_account_creator = linphone_account_creator_new(
LC, [LinphoneManager.instance lpConfigStringForKey:@"xmlrpc_url" inSection:@"assistant" withDefault:@""]
.UTF8String);
NSString *ip = @"SIP地址ip";
NSInteger port = @"SIP地址端口";
NSString *username = @"SIP登錄賬號";
NSString *displayName = @"SIP登錄賬號用戶名";
NSString *pwd = @"SIP登錄密碼";
NSString *domain = [NSString stringWithFormat:@"%@:%ld", ip, port];
LinphoneAccountParams *accountParams = linphone_core_create_account_params(LC);
LinphoneAddress *addr = linphone_address_new(NULL);
linphone_address_set_username(addr, username.UTF8String);
linphone_address_set_port(addr, port);
linphone_address_set_domain(addr, ip.UTF8String);
if (displayName && ![displayName isEqualToString:@""]) {
linphone_address_set_display_name(addr, displayName.UTF8String);
}
linphone_account_params_set_identity_address(accountParams, addr);
// set transport
// 使用UDP方式登錄
NSString *type = @"UDP";
LinphoneAddress *transportAddr = linphone_address_new([NSString stringWithFormat:@"sip:%s;transport=%s", domain.UTF8String, type.lowercaseString.UTF8String].UTF8String);
linphone_account_params_set_routes_addresses(accountParams, bctbx_list_new(transportAddr));
linphone_account_params_set_server_addr(accountParams, [NSString stringWithFormat:@"%s;transport=%s", domain.UTF8String, type.lowercaseString.UTF8String].UTF8String);
linphone_address_unref(transportAddr);
linphone_account_params_set_publish_enabled(accountParams, FALSE);
linphone_account_params_set_register_enabled(accountParams, TRUE);
// 設(shè)置ice關(guān)閉,不然通話保持后屯断,不能再次接回
LinphoneNatPolicy *policy = linphone_core_create_nat_policy(LC);
linphone_nat_policy_enable_stun(policy, FALSE); // We always use STUN with ICE
linphone_nat_policy_enable_ice(policy, FALSE);
linphone_account_params_set_nat_policy(accountParams, policy);
LinphoneAuthInfo *info =
linphone_auth_info_new(linphone_address_get_username(addr), // username
NULL, // user id
pwd.UTF8String, // passwd
NULL, // ha1
linphone_address_get_domain(addr), // realm - assumed to be domain
linphone_address_get_domain(addr) // domain
);
linphone_core_add_auth_info(LC, info);
linphone_address_unref(addr);
LinphoneAccount *account = linphone_core_create_account(LC, accountParams);
linphone_account_params_unref(accountParams);
if (account) {
if (linphone_core_add_account(LC, account) != -1) {
linphone_core_set_default_account(LC, account);
// reload address book to prepend proxy config domain to contacts' phone number
// todo: STOP doing that!
// 添加成功
} else {
}
} else {
}
通知監(jiān)聽賬號登錄成功
[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(registrationUpdate:)
name:kLinphoneRegistrationUpdate
object:nil];
...
- (void)registrationUpdate:(NSNotification *)notif
{
LinphoneAccount *account = linphone_core_get_default_account(LC);
LinphoneRegistrationState state = linphone_account_get_state(account);
switch (state) {
case LinphoneRegistrationOk:
{
[self successToSipRegister];
}
break;
case LinphoneRegistrationNone:
case LinphoneRegistrationCleared:
break;
case LinphoneRegistrationFailed:
{
[self failedToSipRegister];
}
break;
case LinphoneRegistrationProgress:
break;
default:
break;
}
}
二、退出登錄
[[LinphoneManager instance] removeAllAccounts];