Skip to content

Latest commit

 

History

History
106 lines (64 loc) · 3.24 KB

chapter01.md

File metadata and controls

106 lines (64 loc) · 3.24 KB

第1章 创建项目并集成LeanCloud SDK

注册LeanCloud并创建项目

  • 访问https://leancloud.cn/ 并注册账号

  • 登陆并进入控制台,选择【中国华东节点】节点,我的机器其他节点测试连接失败:

  • 创建新应用【Instagram】

  • 输入新应用名称

  • 创建成功后显示应用列表

  • 查看应用Key

新建 Instagram 项目

  • 新建项目

  • 项目信息

  • 项目文件结构

将LeanCloud SDK 集成到 iOS 项目中

关闭项目

  • 在工程文件夹下新增 Podfile内容如下
platform :ios, '12.1'
use_frameworks!

target 'Instagram' do
   pod 'LeanCloud'
end
  • 在终端中执行安装命令
pod install
  • 安装结果

完成后会新建两个文件“Instagram.xcworkspace”和“Podfile.lock”,同时新建一个文件夹Pods,如图所示:

重新打开项目

  • 点击“Instagram.xcworkspace”文件,打开项目

修改源代码

  • 修改 AppDelegate.swfit 的 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool 方法
func application(_ application: UIApplication, didFinishLaunchingWithOptions 
	launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    LeanCloud.initialize(applicationID: "Your App ID", applicationKey: "Your App Key")
    
    /* Create an object. */
    let object = LCObject(className: "Post")
    object.set("words", value: "Hello World!")
    /* Save the object to LeanCloud application. */
    object.save { result in
        switch result {
        case .success: print("Success")
        case .failure: print("Failure")
        }
    }
    
    return true
}
  • 运行结果

  • 数据成功写入LeanCloud