#import "ViewController.h"
#import <BmobSDK/Bmob.h>
@interface Viewcontroller ()
{
Nsmutabledictionary *dic;
}
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
DIC = [Nsmutabledictionary dictionary];
/*
--------------add a set of data to Bmob
Add a piece of data to Gamescore table with a score of playername of 78
Bmobobject *gamescore = [Bmobobject objectwithclassname:@ "Zhenshi"];
[Gamescore setobject:@ "true" forkey:@ "Wukun"];
[Gamescore setobject:@100 forkey:@ "ww"];
[Gamescore setobject:[nsnumber Numberwithbool:yes] forkey:@ "Cheatmode"];
[Gamescore saveinbackgroundwithresultblock:^ (BOOL issuccessful, Nserror *error) {
To operate
}];
-----------Find Data
Bmobquery *bquery = [bmobquery querywithclassname:@ "Gamescore"];
Finding data for Gamescore tables
[Bquery findobjectsinbackgroundwithblock:^ (Nsarray *array, Nserror *error) {
For (Bmobobject *obj in array) {
Print PlayerName
NSLog (@ "obj.playername =%@", [obj objectforkey:@ "playername"]);
Print Objectid,createdat,updatedat
NSLog (@ "Obj.objectid =%@", [obj objectId]);
NSLog (@ "Obj.createdat =%@", [obj Createdat]);
NSLog (@ "Obj.updatedat =%@", [obj Updatedat]);
}
}];
It is important to note that:
1. By default, the system does not actually return all the data, but instead returns 10 data records by default, and you can set the number of records returned by the Setlimit method. For more details, click to view the section on paging queries.
2. When querying a system table of the user table, the return is an array of bmobuser, a device table, and a role table.
3. Query the user table, the device table, the role table is:
Bmobquery *bquery = [bmobuser query]; User table
Bmobquery *bquery = [bmobinstallation query]; Equipment table
Bmobquery *bquery = [bmobrole query]; Role table
*/
Add a piece of data to Gamescore table with a score of playername of 78
Bmobobject *gamescore = [Bmobobject objectwithclassname:@ "Gamescore"];
[Gamescore setobject:@ "Xiao Ming" forkey:@ "playername"];
[Gamescore setobject:@78 forkey:@ "Score"];
[Gamescore setobject:[nsnumber Numberwithbool:yes] forkey:@ "Cheatmode"];
[Gamescore saveinbackgroundwithresultblock:^ (BOOL issuccessful, Nserror *error) {
To operate
// }];
NSLog (@ "%@", Gamescore);
-----------Find Data
Name of the Gamescore table
PlayerName the name of the second column
Objectid first Column
Createdat third column
Updatedat Fourth Column
Bmobquery *bquery = [bmobquery querywithclassname:@ "MyImage"];
Finding data for Gamescore tables
[Bquery findobjectsinbackgroundwithblock:^ (Nsarray *array, Nserror *error) {
For (Bmobobject *obj in array) {
Print PlayerName
NSLog (@ "obj.playername =%@", [obj objectforkey:@ "Image1"]);
Print Objectid,createdat,updatedat
NSLog (@ "Obj.objectid =%@", [obj objectId]);
NSLog (@ "Obj.createdat =%@", [obj Createdat]);
NSLog (@ "Obj.updatedat =%@", [obj Updatedat]);
[DiC setobject:[obj objectforkey:@ "Image1"] forkey:@ "Image1"];
[DiC setobject:[obj objectforkey:@ "Image2"] forkey:@ "Image2"];
NSLog (@ "---0099%@", dic);
Network requests
Nsurl *url = [Nsurl urlwithstring:dic[@ "Image1"];
NSData *data = [NSData Datawithcontentsofurl:url];
Nsurl *URL1 = [Nsurl urlwithstring:dic[@ "Image2"];
NSData *data1 = [NSData DATAWITHCONTENTSOFURL:URL1];
Nsarray *array = @[data,data1];
for (int i = 0; i < 2; i + +) {
Uiimageview *image = [[Uiimageview alloc]initwithframe:cgrectmake (100+ (20+100) *i, 100,100)];
Image.image = [UIImage imagewithdata:array[i]];
[Self.view Addsubview:image];
}
}
}];
Nsurl *URL1 = [Nsurl urlwithstring:@ "http://pic26.nipic.com/20121223/9252150_195341264315_2.jpg"];
NSData *data1 = [NSData DATAWITHCONTENTSOFURL:URL1];
//
Uiimageview *image = [[Uiimageview alloc]initwithframe:cgrectmake (10, 100, 100,100)];
Image.backgroundcolor = [Uicolor Redcolor];
Image.image = [UIImage imagewithdata:data1];
[Self.view Addsubview:image];
}
Bmob Extract pictures (web image)