Integrate the SDK
Update time: 2023/02/09 03:53:39
This document describes how to integrate Instant Messaging SDK (NIM SDK) into your project.
Set up a development environment
iPhone or iPad devices with iOS 8.0 and later
Procedure
Step 1: Create a new project (optional)
This step creates a new project. If you already integrate NIM SDK into an existing project, ignore this step
1. Launch Xcode and select File > New > Project in the upper left corner.2. In the list that appears, select the iOS platform, and select App under Application.
3. Configure the new project and click Next.
Product Name and Organization Identifier are required.
4. Select the storage path and click Create to create a project.
Step 2: Integrate the SDK
You can integrate NIM SDK using the following two methods. Select one method as required.
-
Automatic integration of the NIM SDK using
CocoaPods
(recommended). -
Manually integrate NIM SDK.
Integrate the SDK using CocoaPods
-
After installing CocoaPods, run the following command in the project directory to create a Podfile.
objc
pod init
-
Add the resources in the Podfile.
Keywords for
CocoaPods
integration:Keyword Resources NIMSDK_LITE NIM SDK that has the NetEase Object Storage (NOS) capability by default. NIMSDK_LIET/FCS NIM SDK that has AWS S3 file storage capability by default NIMKit NIMSDK_LITE+NIM_iOS_UIKit+custom version third-party dependency NIMKit/Lite_Free NIMSDK_LITE+NIM_iOS_UIKit+unlimited third party dependency If you only need the instant messaging capabilities (NOS) and do not need the
NIM_iOS_UIKit
component, you can specify the setting inPodfile
:pod 'NIMSDK_LITE'
-
Run the following command to update the local repository and view the version information. For the information about the newest version, see Changelog.
pod search NIMSDK_LITE //Search the resource version in the repository pod repo update // Update the local repository.
-
Run the following command to install NIM SDK:
pod install
Manual integration
- Download the required SDK.
Framework | Description |
---|---|
NIMSDK | Basic messaging capability |
NIMNOS | NOS file storage capabilitythat works with NIMSDK (not NIMFCS) |
NIMFCS | AWS S3 file storagecapability that works with NIMSDK (notNIMNOS) |
:::note note
- NIMSDK must be used with NIMNOS or NIMFCS and cannot be used alone.
- If your app serves users in China, use NIMSDK and NIMNOS Frameworks.
- If users of your app are distributed out of China, use NIMSDK and NIMFCS Frameworks.
- NIMNOS and NIMFCS cannot be used together.
:::
-
Copy the decompressed framework files to the project folder.
-
Select the TARGETS > Project Name > General > Frameworks, Libraries, and Embedded Content menu, add the corresponding framework files, and set the Embed property to Embed & Sign, so that the dynamic libraries and application signature are consistent. The SDK is imported.
What’s next
After the SDK is integrated, you must initialize the SDK.
Demo download
IM Demo is open sourced on GitHub. You can download the source code for reference.
FAQ
Why packaging fails
If you integrate the SDK manually, packaging may fail because the library contain the emulator version. You must remove the emulator version before packaging
- Create the
nim_strip_archs.sh
script in the specified directory, such asSupporting Files
- Add a process in
Build Phases
ofNew Run Script Phase
type. - Add the following content to the project. For example,
/bin/sh "${SRCROOT}/NIMDemo/Supporting Files/nim_strip_archs.sh"
./bin/sh the path of your script.
- Copy the following content to the script.
sh
#!/bin/sh # Strip invalid architectures strip_invalid_archs() { binary="$1" echo "current binary ${binary}" # Get architectures for current file archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | rev)" stripped="" for arch in $archs; do if ! [[ "${ARCHS}" == *"$arch"* ]]; then if [ -f "$binary" ]; then # Strip non-valid architectures in-place lipo -remove "$arch" -output "$binary" "$binary" || exit 1 stripped="$stripped $arch" fi fi done if [[ "$stripped" ]]; then echo "Stripped $binary of architectures:$stripped" fi } APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}" # This script loops through the frameworks embedded in the application and # removes unused architectures. find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK do FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable) FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME" echo "Executable is $FRAMEWORK_EXECUTABLE_PATH" strip_invalid_archs "$FRAMEWORK_EXECUTABLE_PATH" done