iOS
Getting started with our tutorials
Swift liblinphone tutorials for IOS allows developer to experiment with simple applications that covers the most common usages : call, chat, push notifications...
Adding the linphone-sdk dependency to your iOS project using Swift Package Manager
Since linphone-sdk version 5.4 and above the linphone-sdk can be added to you iOS projects using swift package manager.
To use the public linphone-sdk Swift Package you can follow these steps
- Open your Xcode Project
- Menu File -> Add Package Dependencies
- On top right entry field enter https://gitlab.linphone.org/BC/public/linphone-sdk-swift-ios
- Choose your branch (by default it is the stable branch, but you can choose alpha or beta or with no video flavour - see below for available branches).
- Select your application target (if you have multiple you need to repeat these steps for each).
- in your classes add statements: import linphonesw (or linphone for C functions)
- Start using linphone-sdk functions
Note 1: that it might be necessary to do the following steps if the app builds but immediately stops not finding a framework : Open the "Build Settings" tab Search for "Runpath Search Paths" (LD_RUNPATH_SEARCH_PATHS) Ensure it contains: @loader_path/Frameworks
Note 2: sometimes Xcode adds multiple times the linphonesw library. If you get compilation errors you can check your Target Build Phases / Link Binary With Libraries section, and make sure linphonesw is there only once. If it is present multiple times it usually helps to remove all instances and re-add the package dependency.
Note 3: locally built sdk with ios-sdk preset will also generate a local swift package that can be used inside your application. The package will be located under your build folder under the name of linphone-sdk-swift-ios and contains a README file.
Available branches :
branch stable -> the currently stable linphone-sdk
branch beta -> the linphone-sdk currently in beta phase
branch alpha -> the master branch of linphone-sdk
branch novideo/stable -> similar to stable but with no video functions (smaller SDK)
branch novideo/beta -> similar to beta but with no video functions (smaller SDK)
branch novideo/alpha -> similar to alpha but with no video functions (smaller SDK)
Adding the liblinphone dependency to your iOS project using Cocoapods
Liblinphone for iOS is still 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 Cocoapods
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' , '~>5.3.0'
end
To install or update the liblinphone version, do the following command
pod install
And you're done.
Some alpha (development versions) of liblinphone may also be available. To get them, replace the line:
pod 'linphone-sdk' , '~>5.3.0'
by
followed by:
Compiling linphone-sdk
Linphone-sdk is the name of the git project that contains liblinphone and all its dependencies.
Compilation instructions of the SDK are available at: linphone-sdk/README.md
Once done, cocoapods needs to be invoked to update the Xcode workspace to use your locally built linphone-sdk, as follows:
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.
Using liblinphone
Liblinphone has a C API, suitable to be used with Objective-C, and a modern Swift API. To use in swift, import the liblinphone swift module in your source file using
API documentation
You can find the liblinphone C API documentation here.
For Swift, online documentation is available here . In addition, this iOS sample app shows how to use liblinphone in a Swift project.
SDK 5.0 and newer features
Automatic iterate()
The newly added auto iterate mode is enabled by default on Android & iOS, but you can disable it with either core.setAutoIterateEnabled(false) method.
You can also configure that behavior in the config file like this:
auto_iterate=0
If you forgot to disable it in the Core and you kept your existing code for scheduling the iterate nevermind, it will be of no consequence.
Foreground / Background modes
Previously developpers had to create code to detect whether the app was in foreground or background and call core.enterBackground() or core.enterForeground() accordingly.
This is no longer required as the liblinphone will do it by itself.
Integrating push notifications and CallKit
Push notifications integrations are a more advanced features, and you will find explanations in great details here. It is recommended that you have a look at the CallKit tutorial and the Remote Notifications tutorial if you wish for a simple integration of these features in your app.
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"]);
}
}