Search code examples
objective-cxcodemacoslinphonelinphone-sdk

Linphone SDK OS X - vcard_grammar


I’m trying to integrate linphone-sdk-Mac from https://download.linphone.org/releases/macosx/sdk/ to my objective c app. Basically what I’m doing is extracting zip file and import framework files to my project and then change all frameworks to “embed and sign” and then compile. Program runs fine until I try to create the core, even using “ linphone_factory_create_core_with_config_3” or “ linphone_factory_create_core_3”, they all crash with the same error, that is “could not load grammar vcard_grammar because the file could not be located”. Already tried to put grammar files in several places of the project, on different versions, including last one, but with no luck. Anyone know anyway to solve this?

Sample code:

LinphoneFactory *factory = linphone_factory_get();

NSString *linphonecfg = [LinphoneManager bundleFile:@"linphonerc"];
NSString *fileStr = [NSString stringWithContentsOfFile:linphonecfg encoding:NSUTF8StringEncoding error:nil];

configDb = linphone_config_new_from_buffer(fileStr.UTF8String);
theLinphoneCore = linphone_factory_create_core_with_config_3(factory, configDb, NULL);

Already tried to compile linphone-desktop but that is failing in random places every time I try to compile it, so could not solve that way.

Thanks


Solution

  • So after a lot of tinkering with the SDK, I've figured out to fix the vCard issue and compile properly without it on macOS with Swift/Objective-C (for arm64 and x86_x64).

    Compiling SDK

    1. Install the following dependencies with homebrew:

      brew install pkg-config cmake doxygen nasm yasm
      
    2. Install pip3/python3 (if you haven't already) and it's dependencies:

      curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
      python3 get-pip.py
      pip3 install pystache
      pip3 install six
      
    3. Clone the latest Linphone SDK and it's dependencies recursively

      git clone --recursive https://gitlab.linphone.org/BC/public/linphone-sdk
      
    4. Make and set the build directory (-DENABLE_VCARD=OFF is the key here):

      mkdir build && cd build
      cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DENABLE_VCARD=OFF ..
      cmake --build .
      

    Xcode Integration

    (if the build succeeded, hopefully)

    1. In your build folder, go into your linphone-sdk/desktop folder
    2. You should see a couple of different folder but the most important ones are Frameworks and share
    3. Add the Frameworks and share folder into your Xcode project with the following options checked: xcode_copy_options
    1. If you're using Swift, you will need to create a Objective-C bridging header with the following lines to avoid a giant list of errors in your LinphoneWrapper.swift in the share/linphonesw folder:
    #import "linphone/factory.h"
    #import "linphone/types.h"
    
    #import "linphone/core.h"
    #import "linphone/call.h"
    #import "linphone/tunnel.h"
    #import "linphone/wrapper_utils.h"
    #import "linphone/core_utils.h"
    #import "linphone/vcard.h"
    
    #import "belle-sip/object.h"
    #import "bctoolbox/list.h"
    #import "mediastreamer2/msfactory.h"
    
    1. In the Frameworks, Libraries, and Embedded Content section of your apps target, every framework should be "Embed & Sign".

    2. Try compiling and accessing Core, Factory, etc... in a Swift file and it should work, if it doesn't, comment below and I'll try to help you out!