pod 'LeanCloud/Foundation' # (required) LeanStorage, SMS, LeanEngine etc.
pod 'LeanCloud/RTM' # (optional) LeanMessage, LiveQuery
# LeanCloud/RTM depends on LeanCloud/Foundation, so their versions must be consistent.
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 before LCApplication.default.set; only needs to be called once
LCApplication.logLevel = .all
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:
do {
let testObject = LCObject(className: "TestObject")
try testObject.set("words", value: "Hello world!")
let result = testObject.save()
if let error = result.error {
print(error)
}
} catch {
print(error)
}
Hit Run to start debugging. This can be done in either a host machine or virtual machine.
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 Swift 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
You can use CocoaPods or Swift Package Manager to manage your project's dependencies.
Swift Package Manager
Just add the swift-sdk repository.
CocoaPods
Add the following pods into the
target
ofPodfile
:or use the Subspecs way:
Then install the SDK with the following command:
Or
See official documentation for the differences between them.
After installing the SDK, you can open your project with
<PROJECT_NAME>.xcworkspace
under the root directory of your project.Installing Manually
Download SDK
Initializing Your Project
To begin with, get your App ID and App Key from your app's Dashboard > Settings > App Keys.
Add the following line to the top of
AppDelegate.swift
:Then add the code below into the function
application(_:didFinishLaunchingWithOptions:)
: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:
Then add the following code into your project:
Hit
Run
to start debugging. This can be done in either a host machine or 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.