iOS - BMOB 云数据

#pragma mark---bmob---

[BmobregisterWithAppKey:@"491a56dc15ca8e6e8fad1803f029c908"];

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

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

[gameScoresetObject:@"小明"forKey:@"playerName"];

[gameScoresetObject:@78forKey:@"score"];

[gameScoresetObject:[NSNumbernumberWithBool:YES]forKey:@"cheatMode"];

[gameScoresaveInBackgroundWithResultBlock:^(BOOLisSuccessful,NSError*error) {

//进行操作

}];

#pragma mark查找GameScore表

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

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

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

if(error){

//进行错误处理

}else{

//表里有id为0c6db13c的数据

if(object) {

//得到playerName和cheatMode

NSString*playerName =

[objectobjectForKey:@"playerName"];

BOOLcheatMode =

[[objectobjectForKey:@"cheatMode"]boolValue];

NSLog(@"%@----%i",playerName,cheatMode);

}

}

}];

#pragma mark--修改数据--

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

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

//没有返回错误

if(!error) {

//对象存在

if(object) {

BmobObject*obj1 = [BmobObjectobjectWithoutDatatWithClassName:object.classNameobjectId:object.objectId];

//设置cheatMode为YES

[obj1setObject:[NSNumbernumberWithBool:NO]forKey:@"cheatMode"];

//异步更新数据

[obj1updateInBackground];

}

}else{

//进行错误处理

}

}];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容