与时俱进的IT

UI(二十四)BMOB 云数据

2018-07-30  本文已影响0人  社会主义顶梁鹿

#pragma mark---bmob---

    [Bmob registerWithAppKey:@"491a56dc15ca8e6e8fad1803f029c908"];

#pragma mark 往GameScore表添加一条数据

 BmobObject *gameScore = [BmobObject objectWithClassName:@"GameScore"];

[gameScore setObject:@"小明" forKey:@"playerName"];

[gameScore setObject:@78 forKey:@"score"];

[gameScore setObject:[NSNumber numberWithBool:YES] forKey:@"cheatMode"];

[gameScore saveInBackgroundWithResultBlock:^(BOOLisSuccessful, NSError *error) {

 //进行操作

    }];

#pragma mark 查找GameScore表

 BmobQuery *bquery = [BmobQuery queryWithClassName:@"GameScore"];

 //查找GameScore表里面id为0c6db13c的数据

[bquery getObjectInBackgroundWithId:@"6899bf70af"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);

            }

        }

    }];

#pragma mark--修改数据--

 //查找GameScore表里面id为0c6db13c的数据

[bquery getObjectInBackgroundWithId:@"6899bf70af"block:^(BmobObject *object,NSError *error){

 //没有返回错误

 if (!error) {

 //对象存在

 if (object) {

BmobObject *obj1 = [BmobObject objectWithoutDatatWithClassName:object.className objectId:object.objectId];

//设置cheatMode为YES

[obj1 setObject:[NSNumber numberWithBool:NO] forKey:@"cheatMode"];

//异步更新数据

[obj1 updateInBackground];

            }

        }else{

 //进行错误处理

        }

    }];

}

-------------------------------------------------------------------

http://docs.bmob.cn/ios/developdoc/index.html?menukey=develop_doc&key=develop_ios#index_短信服务

上一篇 下一篇

猜你喜欢

热点阅读