OC 项目引入 LeanCloud

发表于 2018-09-08   |   分类于 Objectiv-C 课程

安装

  • 创建一个 Single View Application
  • 项目根目录执行 pod init 生成 Podfile
  • 在 Podfile 中加入 Pod 的代码Podfile
  • 执行 pod install 来安装 Pod。Pod Install
  • 打开项目名.xcworkspace
  • 找到 AppDelegate.m 文件,然后加入如下代码插入代码

至此完成 LeanCloud 的引入

测试

在 初始化的代码下加入调用

调用

然后启动应用,可以在控制台看到输出,以及 LeanCloud 后台看到对象。

console
LeanCloud

涉及到的代码

Podfile

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'

target 'ins-test-oc' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!
        pod 'AVOSCloud'  
        pod 'AVOSCloudIM'
  # Pods for ins-test-oc

end

Appdelete.m

//
//  AppDelegate.m
//  ins-test-oc
//
//  Created by HuanCheng Bai on 2018/9/8.
//  Copyright © 2018年 HuanCheng Bai. All rights reserved.
//

#import "AppDelegate.h"
#import <AVOSCloud/AVOSCloud.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [AVOSCloud setApplicationId:@"3B5SllOK7TgK5xGQTpxXARPH-gzGzoHsz" clientKey:@"9DB0NF42z5uNUlzb6WbeovDE"];
    [AVOSCloud setAllLogsEnabled:YES];

    [AVAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
    AVObject *testObject = [AVObject objectWithClassName:@"TestObject"];
    [testObject setObject:@"bar" forKey:@"foo"];
    [testObject save];
    
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end

参考链接

  1. https://leancloud.cn/docs/start.html
  2. https://cocoapods.org
  3. https://leancloud.cn/docs/leanstorage-started-objc.html

发表新评论

© 2019 Powered by Typecho & Theme 豫ICP备15027577号