How to insert data to Mobile Services - iOS / iPhone (Windows Azure)
How to insert data in Mobile Services - iOS / iPhone (Windows Azure) สรุปวิธีการบันทึก Insert ข้อมูลเข้า Table ของ Mobile Services บน Windows Azure ด้วย iOS / iPhone แบบสั้น ๆ ง่าย ๆ
-(void)addItem:(NSDictionary *)item completion:(QSCompletionBlock)completion
{
// Insert the item into the TodoItem table and add to the items array on completion
[self.table insert:item completion:^(NSDictionary *result, NSError *error)
{
[self logErrorIfNotNil:error];
BOOL goodRequest = !((error) && (error.code == MSErrorMessageErrorCode));
// detect text validation error from service.
if (goodRequest) // The service responded appropriately
{
NSUInteger index = [items count];
[(NSMutableArray *)items insertObject:result atIndex:index];
// Let the caller know that we finished
completion();
}
else{
// if there's an error that came from the service
// log it, and popup up the returned string.
if (error && error.code == MSErrorMessageErrorCode) {
NSLog(@"ERROR %@", error);
UIAlertView *av =
[[UIAlertView alloc]
initWithTitle:@"Request Failed"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil
];
[av show];
}
}
}];
}