Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)sendNewMessageAction {
  2.     if(!newMessage.length && !attachment) {
  3.         [Utility showAlert:NSCSENLocalizedString(@"NEW_MESSAGE_EMPTY_DATA", nil)];
  4.         return;
  5.     }
  6.    
  7.     [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  8.     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
  9.                    ^{
  10.                        // Async part
  11.                        NSDictionary *answer = [[WebService sharedManager] call:@"sendMessage" arguments:@[newMessage.length ? newMessage : @"", [self formatBase64FromAttachment]]];
  12.                        
  13.                        dispatch_async(dispatch_get_main_queue(),
  14.                                       ^{
  15.                                           // Sync part (in main thread)
  16.                                           [MBProgressHUD hideHUDForView:self.view animated:YES];
  17.                                          
  18.                                           if([[AnswerHandler sharedManager] processAnswer:answer]) {
  19.                                               newMessage = @"";
  20.                                               newMessageTextView.text = placeholderString;
  21.                                              
  22.                                               [newMessageTextView endEditing:YES];
  23.                                              
  24.                                               [self deleteAttachmentAction];
  25.                                              
  26.                                               [self loadData];
  27.                                           }
  28.                                       });
  29.                    });
  30. }
  31.  
  32. - (NSString *)formatBase64FromAttachment {
  33.     if(!attachment) {
  34.         return @"";
  35.     }
  36.    
  37.     NSString *imgBase64 = [UIImagePNGRepresentation(attachment) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
  38.    
  39.     NSString * parsedString = [imgBase64 stringByReplacingOccurrencesOfString:@"+" withString:@"-"];
  40.     return [parsedString stringByReplacingOccurrencesOfString:@"/" withString:@"_"];
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement