Bmob的初步使用,Bmob使用
註冊Bmob帳號
在網址欄輸入www.bmob.cn或者在百度輸入Bmob進行搜尋,開啟Bmob官網後,點擊右上方的“註冊”,在跳轉頁面填入你的姓名、郵箱、設定密碼,確認後到你的郵箱啟用Bmob賬戶,你就可以用Bmob輕鬆開發應用
網站後台建立應用
登入帳號進入bmob後台後,點擊後台介面左上方“建立應用”,在彈出框輸入你應用的名稱,然後確認,你就擁有了一個等待開發的應用。
擷取應用密鑰和下載SDK
選擇你要開發的應用,點擊該應用下方對應的“應用密鑰”
匯入後效果如下:
設定應用的BmobKey
一個測試:上傳名字密碼和圖片的一個測試
創一個button 關聯事件:
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; [button setTitle:@"發送" forState:UIControlStateNormal]; button.bounds = CGRectMake(0, 0, 200, 30); button.center = self.view.center; [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button];
- (void)buttonPressed:(UIButton *)sender { [self createBmobObject];// [self addUserInfo];}
-(void)createBmobObject{ //往GameScore表添加一條playerName為小明,分數為78的資料 BmobObject *gameScore = [BmobObject objectWithClassName:@"UserInformation"]; [gameScore setObject:@"你的名字" forKey:@"name"]; [gameScore setObject:@"123" forKey:@"password"]; [gameScore saveInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) { if (isSuccessful) { NSLog(@"成功"); }else { NSLog(@"失敗"); } }]; NSBundle *bundle = [NSBundle mainBundle]; //本地圖片 NSString *fileString = [NSString stringWithFormat:@"%@/image1.jpg" ,[bundle bundlePath] ]; BmobFile *file = [[BmobFile alloc] initWithFilePath:fileString]; [file saveInBackground:^(BOOL isSuccessful, NSError *error) { if (isSuccessful) { [gameScore setObject:file forKey:@"logImage"]; [gameScore updateInBackground]; NSLog(@"成功"); } } withProgressBlock:^(float progress) { }];}
效果: