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:@ 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];
}
}
}];
04-18 04:14
查看更多