I'm facing difficulty sending data via MPC, communication is working correctly between the devices is being printed on a TextView my need is to be presented in a table view, I can add and remove objects from a table view via MPC, does anyone know if it is possible or if it's just the impression the MPC is in TextView.
Thank you.
I thank you.
I will let down my code that sends and receives.
Send data
-(void) inputIDTransporte {
//testando IDController
IDController * idC = [[IDController alloc] init];
[idC loadIdInput:_textView.text];
//mudando mensagem de saida
[idC.idValues replaceObjectAtIndex:9 withObject:_textField.text];
[idC generateIDOutputByComponentsScheme];
NSLog(@"idValues:%@", idC.idValues);
NSLog(@"idOutput:%@", idC.idOutput);
NSLog(@"index9: %@",idC.idValues[9]);
NSString* str= [idC.idValues objectAtIndex:9];
NSData* dataToSend=[str dataUsingEncoding:NSUTF8StringEncoding];
NSArray *allPeers = _appDelegate.mcManager.session.connectedPeers;
NSError *error;
[_appDelegate.mcManager.session sendData:dataToSend
toPeers:allPeers
withMode:MCSessionSendDataReliable
error:&error];
[idC.componentsScheme setValue:str forKey:@"name"];
[self.tableView reloadData];
if (error) {
NSLog(@"%@", [error localizedDescription]);
}
}
Receive data
-(void)didReceiveDataWithNotification:(NSNotification *)notification{
MCPeerID *peerID = [[notification userInfo] objectForKey:@"peerID"];
NSString *peerDisplayName = peerID.displayName;
NSData *receivedData = [[notification userInfo] objectForKey:@"data"];
NSString *receivedText = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
[_tvChat performSelectorOnMainThread:@selector(setText:) withObject:[_tvChat.text stringByAppendingString:[NSString stringWithFormat:@"%@\n", receivedText]] waitUntilDone:NO];
[_tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}