• Bmob 之 简单使用


    1. pod 

      pod 'BmobSDK' 与 pod "BmobSDK" 好像没什么区别

    2. 导入

      在AppDelegate中:

    #import <BmobSDK/Bmob.h>
    
    [Bmob registerWithAppKey:@"申请的Application ID"];

    3. 数据处理

    3.1. 添加

    //往GameScore表添加一条playerName为小明,分数为78的数据
    BmobObject *gameScore = [BmobObject objectWithClassName:@"GameScore"];
    [gameScore setObject:@"小明" forKey:@"playerName"];
    [gameScore setObject:@78 forKey:@"score"];
    [gameScore setObject:[NSNumber numberWithBool:YES] forKey:@"cheatMode"];
    [gameScore saveInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
        //进行操作
    }];

    3.2. 获取

    //查找GameScore表
    BmobQuery   *bquery = [BmobQuery queryWithClassName:@"GameScore"];
    //查找GameScore表里面id为0c6db13c的数据
    [bquery getObjectInBackgroundWithId:@"0c6db13c" block:^(BmobObject *object,NSError *error){
      if (error){
              //进行错误处理
      }else{
            //表里有id为0c6db13c的数据
          if (object) {
                //得到playerName和cheatMode
              NSString *playerName = [object objectForKey:@"playerName"];
              BOOL cheatMode = [[object objectForKey:@"cheatMode"] boolValue];
              NSLog(@"%@----%i",playerName,cheatMode);
          }
      }
    }];

    3.3. 修改

    //查找GameScore表
    BmobQuery   *bquery = [BmobQuery queryWithClassName:@"GameScore"];
    //查找GameScore表里面id为0c6db13c的数据
    [bquery getObjectInBackgroundWithId:@"0c6db13c" block:^(BmobObject *object,NSError *error){
      //没有返回错误
      if (!error) {
          //对象存在
          if (object) {
                BmobObject *obj1 = [BmobObject objectWithoutDatatWithClassName:object.className objectId:object.objectId];
                 //设置cheatMode为YES
              [obj1 setObject:[NSNumber numberWithBool:YES] forKey:@"cheatMode"];
              //异步更新数据
              [obj1 updateInBackground];
          }
      }else{
        //进行错误处理
      }
    }];

    3.4. 删除

    BmobQuery *bquery = [BmobQuery queryWithClassName:@"GameScore"];
    [bquery getObjectInBackgroundWithId:@"0c6db13c" block:^(BmobObject *object, NSError *error){
        if (error) {
            //进行错误处理
        }
        else{
            if (object) {
                //异步删除object
                [object deleteInBackground];
            }
        }
    }];
  • 相关阅读:
    mysql 防止插入某个字段重复的值
    vue 脚手架的目录结构
    搭建Vue 脚手架项目
    flex 布局的页面
    Java List 排序问题
    maven 管理oracle jar
    JPA 注解
    PL/SQL Developer 不显示系统表,默认显示My objects
    jquery面试题
    web前端课程检测2
  • 原文地址:https://www.cnblogs.com/SimonGao/p/5032315.html
Copyright © 2020-2023  润新知