0

MPC 経由でデータを送信する際に問題が発生しています。デバイス間の通信は正常に機能しており、TextView に出力されています。テーブル ビューで表示する必要があります。MPC を介してテーブル ビューからオブジェクトを追加および削除できます。それが可能であるか、それがMPCがTextViewにあるという単なる印象である場合。

ありがとうございました。

感謝します。

送受信するコードを失望させます。

データを送る

-(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]);
}

}

データを受信

-(void)didReceiveDataWithNotification:(NSNotification *)通知{

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];

}

4

1 に答える 1