I haven't written a blog for a long time. This is my first technical blog post after I step into my new job. Before entering a new company, I had a technical layer to prepare for the next iteration, but many things were unexpected, just as I interviewed me as a C # programmer, it is now a full-time IOS development. Switching from C # To Objective-C still has a lot of costs. With Swift launched this year, it will take a long time to learn. In fact, the learning path is long and should not be satisfied with a stage or a specific field. For me, language switching is too common. It is easy to learn a language, but it is not easy to fully master it, just like finding out the temper of a stranger. It's a bit far away. Let's go to the topic today!
PJSIP. If you don't know what it is, it means you don't need to use it, so you don't have to read my article. Since VOIP is needed in the project, the cost of using SIP is relatively small. In Android, Google has built-in support for SIP, IOS is not so lucky, so I found PJSIP, which is a pure C library and is quite beautiful. I have been searching for a long time on the Internet and have not found any entry-level Tutorials that suit me. With my exploration and efforts, I finally came up with a name hall. Congratulations, you don't have to take the detour I 've taken.
The following is the official start step by step:
Step 1: Download
First, go to the official website to download the source code. Here we recommend you download the .tar.bz2 package. After the download is complete, find the corresponding directory and decompress it with tar or graphical operations, here I use the command line method to operate:
$ tar -jxvf pjproject-2.2.1.tar.bz2
Step 2: Compile
First, create a config_site.h file under the pjlib/include/pj/directory, switch to the directory, and use vi or touch to create a file:
$ cd pjlib/include/pj/$ vi config_site.h
According to the official instructions, the content of our document is defined as follows:
#define PJ_CONFIG_IPHONE 1#include <pj/config_site_sample.h>
OK, save and switch back to the main directory (that is, folders in directories such as pjlib, pjmedia, and pjnath). At this time, we can compile the file and there is a premise, you must install XCode Command Line Tools (XCode-> Preferences-> Downloads ).
I386
First, compile the static library of the simulator platform and execute the following three statements:
$ export DEVPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer$ ARCH="-arch i386" CFLAGS="-O2 -m32 -mios-simulator-version-min=5.0" LDFLAGS="-O2 -m32 -mios-simulator-version-min=5.0" ./configure-iphone$ make dep && make clean && make
OK. If there is no problem, the static library of your Simulator version will be compiled. They exist in:
- Pjlib/lib
- Pjlib-util/lib
- Pjmedia/lib
- Pjnath/lib
- Pjsip/lib
- Third_party/lib
These are static libraries that must be used in future SIP development. Currently, this library only supports simulators (you can use the lipo-info command to view them, and only supports i386 ), therefore, we will copy it out. Of course, I have prepared a copy script for you:
#!/bin/bashPJLIB_PATH="./lib/$1/pjlib"PJLIB_UTIL_PATH="./lib/$1/pjlib-util"PJMEDIA_PATH="./lib/$1/pjmedia"PJNATH_PATH="./lib/$1/pjnath"PJSIP_PATH="./lib/$1/pjsip"THIRD_PARTY="./lib/$1/third_party"echo "start coping to $1"rm -rf $PJLIB_PATHrm -rf $PJLIB_UTIL_PATHrm -rf $PJMEDIA_PATHrm -rf $PJNATH_PATHrm -rf $PJSIP_PATHrm -rf $THIRD_PARTYmkdir -p $PJLIB_PATHmkdir -p $PJLIB_UTIL_PATHmkdir -p $PJMEDIA_PATHmkdir -p $PJNATH_PATHmkdir -p $PJSIP_PATHmkdir -p $THIRD_PARTYcp -r ./pjlib/lib/ $PJLIB_PATHcp -r ./pjlib-util/lib/ $PJLIB_UTIL_PATHcp -r ./pjmedia/lib/ $PJMEDIA_PATHcp -r ./pjnath/lib/ $PJNATH_PATHcp -r ./pjsip/lib/ $PJSIP_PATHcp -r ./third_party/lib/ $THIRD_PARTYecho "copy done"
Save the script as copylibs. sh to the main directory (you should know where the main directory is !), Then execute:
$ ./copylibs.sh i386
If you are prompted that the permission is insufficient, use chmod 777 copylibs. sh to grant the maximum access permission to the file. After execution, all generated static libraries are copied to the corresponding location in the lib directory in the main directory.
Armv7
Next, compile the armv7 library and close the console,Note that all are closed before enteringAnd then run the following commands in the main directory:
$ ARCH='-arch armv7' ./configure-iphone$ make dep && make clean && make$ ./copylibs.sh armv7
Armv7s
Compile the armv7s library now. You do not need to close the console this time. Execute the following commands in sequence (errors are reported, but the sample project compilation errors are not related to static link library files ):
$ ARCH='-arch armv7s' ./configure-iphone$ make dep && make clean && make$ ./copylibs.sh armv7s
Arm64
Finally, we have compiled the arm64 Library:
$ ARCH='-arch arm64' ./configure-iphone$ make dep && make clean && make$ ./copylibs.sh arm64
Step 3: Merge static Link Libraries
Now, all the databases we need have been copied to the lib directory. It should be as follows:
#! /Bin/bashOUPUT_PATH = ". /mixed/"XLIPO ="/Applications/Xcode. app/Contents/Developer/Platforms/iPhoneOS. platform/Developer/usr/bin/lipo "for dir in armv7/* do LIB_NAME =$ {dir # */} LIB_OUTPUT =$ {OUPUT_PATH} $ LIB_NAME rm-rf $ LIB_OUTPUT mkdir-p $ LIB_OUTPUT for subdir in $ {dir}/* do AFILE =$ {subdir # */} ARMV7_FILE = ". /armv7/$ LIB_NAME/$ AFILE "ARMV7S_FILE = ". /armv7s/$ LIB_NAME/$ AFILE "ARM64_FILE = ". /arm64/$ LIB_NAME/$ AFILE "i1__file = ". /i386/$ LIB_NAME/$ AFILE "echo" start mixing file: $ AFILE "$ {XLIPO}-arch armv7 $ extract-arch armv7s $ ARMV7S_FILE-arch arm64 $ ARM64_FILE-arch i386 $ i1__file-create-output $ {LIB_OUTPUT}/$ AFILE donedoneecho" all mixed done"
Save the above script to mix. sh In the lib directory, switch cd to the lib directory in the console, and then execute:
./mix.sh
Okay, now everything is done. There will be an extra mixed directory under the lib directory. All the Libraries under this directory contain information about the various architecture versions to appeal, you can use lipo to verify the following:
Note that you must use the lipo under Xcode for both merging and viewing. the lipo that comes with mac is not supported.
If you think it is too difficult to do it yourself, here is a version that has been compiled for you to download and use directly:
Https://github.com/chebur/pjsip
However, I recommend that you do it yourself. If you do it yourself, it will be more interesting to use it ~