There are several ways for you to install our SDK and the most convenient one is to use a package manager.
Installing with Package Manager
The easiest way to integrate our SDK into your project is to use CocoaPods.
Add the following pods into the target of Podfile:
pod 'AVOSCloud' # (required) LeanStorage, SMS, LeanEngine etc.
pod 'AVOSCloudIM' # (optional) LeanMessage
pod 'AVOSCloudLiveQuery' # (optional) LiveQuery
After adding the pods, run pod update or pod install --repo-update under the same directory to complete the installation.
After installing the SDK, you can open your project with <PROJECT_NAME>.xcworkspace under the root directory of your project.
Then check out the version you wish to use. The versions of the SDK are marked with tags so that you can check out the latest version with the following command:
The following two ways can be used to add the SDK into your project. You may select any one of them:
Add the xcodeproj file of the SDK into the project.
Compile the SDK into frameworks and add them to the project.
Integrating xcodeproj
Drag and drop AVOS/AVOS.xcodeproj into the project as a subproject:
Then set up Build Phases for the project. Add the following contents into Link Binary With Libraries:
Here we chose AVOSCloud and AVOSCloudIM as examples of frameworks being used. You can make your selections according to the platform you are building for and the modules you are using.
Adding System Dependencies
Now add the system frameworks and libraries the SDK depends on:
libz
libc++
libicucore
libsqlite3
SystemConfiguration.framework
MobileCoreServices.framework
CoreTelephony.framework
CoreLocation.framework
Like this:
The last step is to add -ObjC into Other Linker Flags.
Before using the APIs provided by the SDK, make sure you have initialized your application with App ID and App Key.
Enabling Debug Logs
You can easily trace the problems in your project by turning debug logs on during the development phase. Once enabled, details of every request made by the SDK along with errors will be output to IDE, browser console, or your app's Dashboard > LeanEngine > App logs.
// Place the line after [AVOSCloud setApplicationId:]; only needs to be called once
[AVOSCloud setAllLogsEnabled:YES];
Make sure debug logs are turned off before your app is published. Failure to do so may lead to the exposure of sensitive data.
Verifying
First of all, make sure you are able to connect to LeanCloud server. You can test it by running the following command:
curl "https://{{domain}}/1.1/date"
If everything goes well, it will return the current date:
Now let's try saving an object to the cloud. Add the following code into the viewDidLoad method or any other method that will be called when the app starts:
This guide is written for the latest version of our SDK. If you encounter any error, please first make sure you have the latest version installed.
401 Unauthorized
If you get a 401 error or see the following content in network logs:
{
"code": 401,
"error": "Unauthorized."
}
It means that the App ID or App Key might be incorrect or don't match. If you have multiple apps, you might have used the App ID of one app with the App Key of another one, which will lead to such error.
Client Cannot Access the Internet
Make sure you have granted enough permissions for your mobile app.
How to Install the Objective-C SDK
Installing SDK
There are several ways for you to install our SDK and the most convenient one is to use a package manager.
Installing with Package Manager
The easiest way to integrate our SDK into your project is to use CocoaPods.
Add the following pods into the
target
ofPodfile
:After adding the pods, run
pod update
orpod install --repo-update
under the same directory to complete the installation.After installing the SDK, you can open your project with
<PROJECT_NAME>.xcworkspace
under the root directory of your project.Installing Manually
Download SDK
Downloading Source Code
Clone the repository of the SDK to the root directory of the project:
Then check out the version you wish to use. The versions of the SDK are marked with tags so that you can check out the latest version with the following command:
Integrating SDK
The following two ways can be used to add the SDK into your project. You may select any one of them:
xcodeproj
file of the SDK into the project.Integrating
xcodeproj
Drag and drop
AVOS
/AVOS.xcodeproj
into the project as a subproject:Then set up Build Phases for the project. Add the following contents into Link Binary With Libraries:
Here we chose
AVOSCloud
andAVOSCloudIM
as examples of frameworks being used. You can make your selections according to the platform you are building for and the modules you are using.Adding System Dependencies
Now add the system frameworks and libraries the SDK depends on:
libz
libc++
libicucore
libsqlite3
SystemConfiguration.framework
MobileCoreServices.framework
CoreTelephony.framework
CoreLocation.framework
Like this:
The last step is to add
-ObjC
into Other Linker Flags.You're all set!
Initializing Your Project
To begin with, get your App ID and App Key from your app's Dashboard > Settings > App Keys.
Import the basic modules into
AppDelegate
:Then paste the following code into the
application:didFinishLaunchingWithOptions:
method:Before using the APIs provided by the SDK, make sure you have initialized your application with App ID and App Key.
Enabling Debug Logs
You can easily trace the problems in your project by turning debug logs on during the development phase. Once enabled, details of every request made by the SDK along with errors will be output to IDE, browser console, or your app's Dashboard > LeanEngine > App logs.
Make sure debug logs are turned off before your app is published. Failure to do so may lead to the exposure of sensitive data.
Verifying
First of all, make sure you are able to connect to LeanCloud server. You can test it by running the following command:
If everything goes well, it will return the current date:
Now let's try saving an object to the cloud. Add the following code into the
viewDidLoad
method or any other method that will be called when the app starts:Hit
Run
to start debugging. This can be done in either a host machine or a virtual machine.Then go to your app's Dashboard > LeanStorage > Data >
TestObject
. If you see the following content, it means that you have correctly installed the SDK.See Debugging if you're not seeing the content.
Debugging
This guide is written for the latest version of our SDK. If you encounter any error, please first make sure you have the latest version installed.
401 Unauthorized
If you get a
401
error or see the following content in network logs:It means that the App ID or App Key might be incorrect or don't match. If you have multiple apps, you might have used the App ID of one app with the App Key of another one, which will lead to such error.
Client Cannot Access the Internet
Make sure you have granted enough permissions for your mobile app.