Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)sendNewMessageAction {
- if(!newMessage.length && !attachment) {
- [Utility showAlert:NSCSENLocalizedString(@"NEW_MESSAGE_EMPTY_DATA", nil)];
- return;
- }
- [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
- ^{
- // Async part
- NSDictionary *answer = [[WebService sharedManager] call:@"sendMessage" arguments:@[newMessage.length ? newMessage : @"", [self formatBase64FromAttachment]]];
- dispatch_async(dispatch_get_main_queue(),
- ^{
- // Sync part (in main thread)
- [MBProgressHUD hideHUDForView:self.view animated:YES];
- if([[AnswerHandler sharedManager] processAnswer:answer]) {
- newMessage = @"";
- newMessageTextView.text = placeholderString;
- [newMessageTextView endEditing:YES];
- [self deleteAttachmentAction];
- [self loadData];
- }
- });
- });
- }
- - (NSString *)formatBase64FromAttachment {
- if(!attachment) {
- return @"";
- }
- NSString *imgBase64 = [UIImagePNGRepresentation(attachment) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
- NSString * parsedString = [imgBase64 stringByReplacingOccurrencesOfString:@"+" withString:@"-"];
- return [parsedString stringByReplacingOccurrencesOfString:@"/" withString:@"_"];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement