我有一个应用程序,其中有两个解析表 - “用户”和“主题”。现在我想要的是,如果有任何用户注册,那么我想创建另一个解析表,它将存储与该用户相关的一些信息,并且主题说主题进度。这是我的代码 -
- (IBAction)signUpFunction {
[self.view endEditing:YES];
NSString *fullName = self.nameTextField.text;
NSString *username = self.usernameTextField.text;
NSString *password = self.passwordTextField.text;
NSString *email = self.emailTextField.text;
if ([username length] == 0 || [password length] == 0 || [email length] == 0 || [fullName length] == 0)
{
[[[UIAlertView alloc] initWithTitle:@"Missing Information"
message:@"Make sure you fill out all of the information!"
delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles:nil] show];
}
else {
PFUser *newUser = [PFUser user];
newUser.username = username;
newUser.password = password;
newUser.email = email;
newUser[@"fullName"] = fullName;
[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (error) {
[[[UIAlertView alloc] initWithTitle:@"Error!"message:[error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show ];
}
else
{
PFQuery *topicsQuery = [PFQuery queryWithClassName:@"Topic"];
[topicsQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (error) {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
else {
for (unsigned int i = 0; i < objects.count; i++) {
PFObject *object = objects[i];
PFObject *topicProgressForUser = [PFObject objectWithClassName:@"QuizProgress"];
[topicProgressForUser setObject:[PFUser currentUser] forKey:@"user"];
[topicProgressForUser setObject:object forKey:@"topic"];
if ([object[@"fullAccess"] isEqualToString:@"Yes"]) {
[topicProgressForUser setObject:@"Free" forKey:@"purchased"];
} else {
[topicProgressForUser setObject:@"No" forKey:@"purchased"];
}
[topicProgressForUser setObject:0 forKey:@"questionsSolved"];
[topicProgressForUser setObject:0 forKey:@"attempts"];
[topicProgressForUser setObject:0 forKey:@"resultInPercentage"];
[topicProgressForUser setObject:@"Basic" forKey:@"achievement"];
[topicProgressForUser setObject:NO forKey:@"generateCertificate"];
[topicProgressForUser saveEventually];
}
}
}]; // topic block
}
}]; // signup block
}
}
我不认为我通过单独保存每个 pfobject 来使用正确的数据保存标准来解析云。如果在保存对象的过程中失去了互联网连接怎么办?谁能帮助我使用正确且快速的方法将多个 pfobject 数据保存到解析云中的新表中。