iOS
How to use liblinphone on IOS
liblinphone SDK for iOS is available using Cocoapods, the de-facto standard in the Apple developer world for "dependency management for Swift and Objective-C". Liblinphone can also be compiled from the sources.
Using the SDK for an Objective-C Xcode project
For a project named "Myproject"
open Myproject/, use commands:
Modify the generated Podfile according to your project:
##For macosx
# platform :osx, '10.9'
#source "https://gitlab.linphone.org/BC/public/podspec-macos.git"
#For iOS
platform :ios, '9.0'
source "https://gitlab.linphone.org/BC/public/podspec.git"
target 'Myproject' do
use_frameworks!
# Pods for Myproject
pod 'linphone-sdk' , '4.2'
end
To install or update the liblinphone version, do the following command
pod install
Using SDK in a Swift Xcode project
liblinphone is also available as a pre-release version with a Swift API. To get it, replace the line:
pod 'linphone-sdk' , '4.2'
by
followed by:
Then, import the swift module in your project
Compiling the liblinphone SDK
Compilation instructions are available at: linphone-sdk/README.md
To use it, in Podfile replace line:
pod 'linphone-sdk' , '4.2'
by
where <path to linphone-sdk-ios> is your build directory of the linphone-sdk project, containing the linphone-sdk.podspec file and a linphone-sdk output directory comprising built frameworks and resources.
followed by:
Documentation
You can find the liblinphone C API documentation here.
For Swift, online documentation is available here
Handling liblinphone log
In order to see liblinphone logs in your IOS app (for example in your Xcode console) follow these steps :
Put in your code at the launching of the app :
This will make the liblinphone logs to call your_log_handler and so be processed as a log from your app.
You can set the liblinphone log level by using the functions documented here.
IOS log handler for liblinphone
Once you have set your log handler, you need to process liblinphone log in order to incorporate them into your app logs.
Here is a short example of how to manage liblinphone log into an IOS app :
NSString *format = [[NSString alloc] initWithUTF8String:fmt];
NSString *formatedString = [[NSString alloc] initWithFormat:format arguments:args];
NSString *lvl;
if (!domain)
domain = "lib";
// since \r are interpreted like \n, avoid double new lines when logging network packets (belle-sip)
// output format is like: I/ios/some logs. We truncate domain to **exactly** DOMAIN_SIZE characters to have
// fixed-length aligned logs
switch (lev) {
case ORTP_FATAL:
lvl = @"Fatal";
break;
case ORTP_ERROR:
lvl = @"Error";
break;
case ORTP_WARNING:
lvl = @"Warning";
break;
case ORTP_MESSAGE:
lvl = @"Message";
break;
case ORTP_DEBUG:
lvl = @"Debug";
break;
case ORTP_TRACE:
lvl = @"Trace";
break;
case ORTP_LOGLEV_END:
return;
}
if ([formatedString containsString:@"\n"]) {
NSArray *myWords = [[formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"]
componentsSeparatedByString:@"\n"];
for (int i = 0; i < myWords.count; i++) {
NSString *tab = i > 0 ? @"\t" : @"";
if (((NSString *)myWords[i]).length > 0) {
NSLog(@"[%@] %@%@", lvl, tab, (NSString *)myWords[i]);
}
}
} else {
NSLog(@"[%@] %@", lvl, [formatedString stringByReplacingOccurrencesOfString:@"\r\n" withString:@"\n"]);
}
}
Full ipv6 support
To comply with Apple requirements, you will need to:
- Update your Linphone-iphone application to 3.13.9 minimum.
- Make sure not to disable IPV6 accidentally in the application, with
linphone_core_enable_ipv6()or by setting
ipv6=0 in
[net]
section of your linphonerc default or factory configuration files.
ipv6=1becomes the default in the 3.3.19 linphone-iphone release.
App upgrade
- For app upgrades, since version 3.13.9 liblinphone automatically switches on IPV6 during installation.
Server side
- Thanks to NAT64/DNS64, IPV4 SIP servers can still be used without modifications, assuming that there are prepared to receive IPV6 addresses in both, VIA, Contact and SDP fields.
- As NAT64 implementation leverages features only available since 9.x (I.E NAT64 aware getaddrinfo), NAT64 is only supported on IOS version >= 9.x.
Testing
- Macos 10.11 provides a way to create a testing IPV6 NAT64/DNS64 network. See Test for IPv6 DNS64/NAT64 Compatibility Regularly for details
IOS 10
What's new in Linphone
- It is no longer possible to listen to a SIP socket in order to detect incoming calls, or new messages, when the application is in background. Now using the push notifications is the only way to do so.
- Linphone uses VoIP push notifications (from the PushKit framework), in replacement of remote notifications and VoIP sockets, since commit : f84fb0bc0fe5cfa34b0029cb775668cd96a13ce3
- For IOS 10 and more a new parameter is needed to register for push notifications : pn-token. When registering for push notifications, it is necessary to add "pn-timeout=0" to the request so that the push gateway sends the notifications as soon as possible.
- FlexiSIP supports VoIP push notifications since commit : a50538897674b2c8cb723e73f6e9d6a969e0b6e0
- Please find more information about push notifications in FlexiSIP here.
CallKit Integration
- Since IOS 10, apple provides the CallKit framework. This framework is used to integrate VoIP applications in the native UI of the device. It allows, for instance, to display incoming calls and answer them when the application is killed or in background, or when the device is locked.
- In order to implement CallKit in an application based on Liblinphone, follow these steps :
- Add the CallKit framework into your application
- Implement the CXProviderDelegate protocol within your ApplicationDelegate
- When answering a call, CallKit needs to start the audio session soon. You need to set your AVAudioSession active into the handler of the report incoming call callback as follow :
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
//Configure audio session here
[audioSession setActive:TRUE error:nil];
}];
- CallKit needs to activate the AVAudioSession before you can start/accept/resume a call, therefore it is advised to wait for provider:provider didActivateAudioSession:audioSession to answer before doing so.