i have implemented some code of file transfer by using this tutorial :
Please Click Here.
and the code which i am using :
- (void)sendToOther
Note: My XEP-0096 implementation is different from your's. Any way you created session so just get that ID It may help you:
- (BOOL)xmppStream:(XMPPStream *)sender didReceiveIQ:(XMPPIQ *)iq
{
//**************** Handling the file transfer task *****************//
NSLog(@"---------- Check if this IQ is for a File Transfer ----------");
NSString *myFileTransferID = YOUR_SESSION_ID_GET_FROM_XEP--0096//[xmppFileTransfer xmppFileTransferResponse:(XMPPIQ *)iq];
if ([myFileTransferID length]>0) {
// Get the file size
NSXMLElement *si = [iq elementForName:@"si"];
NSXMLElement *file = [si elementForName:@"file"];
if (file) {
//All are the attribute of file while creating section Id you need to take car for that
filesize = [file attributeUInt32ValueForName:@"size"];
received_FileOwner = [iq fromStr];
received_FileType = [si attributeStringValueForName:@"mime-type"];
received_FileName = [file attributeStringValueForName:@"name"];
}
}
if([myFileTransferID length] > 0 && [[iq type] isEqualToString:@"result"]) {
// Create bytestream socket for File Transfer via XEP-0065
TURNSocket *turnSocket = [[TURNSocket alloc] initWithStream:xmppStream toJID:[iq from] fileTransferSID:myFileTransferID];
[turnSockets addObject:turnSocket];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
}
else if([myFileTransferID length] > 0 && [[iq type] isEqualToString:@"set"]) {
if ([TURNSocket isNewStartTURNRequest:iq]) {
NSLog(@"TURN Connectio started:: to establish:: incoming file transfer request..");
TURNSocket *turnSocket = [[TURNSocket alloc]initWithStream:sender incomingTURNRequest:iq withSessionID:myFileTransferID];
[turnSocket startWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[turnSockets addObject:turnSocket];
}
}
}
TurnSocket delegates
- (void)turnSocket:(TURNSocket *)sender didSucceed:(GCDAsyncSocket *)socket
{
NSLog(@"Socket Suceeed Port For File Transfer: %d",socket.localPort);
DDLogInfo(@"TURN Connection succeeded!");
DDLogInfo(@"You now have a socket that you can use to send/receive data to/from the other person.");
if ([imageDataFile length]>0) {
// fileTransferData data to write
[socket fileTransferData withTimeout:200.0f tag:TAG_FILETRANSFER_STREAM];
// [turnSockets removeObject:sender];
}
else {
fileTransferData = [[NSMutableData alloc]init];
[socket readDataToLength:filesize withTimeout:290.0f tag:0];
}
}
- (void)turnSocketDidFail:(TURNSocket *)sender
{
DDLogInfo(@"TURN Connection failed!");
[turnSockets removeObject:sender];
}
- (void)readRecievedData:(NSData*)data withTurnSocket:(TURNSocket *)receiver {
[fileTransferData appendData:data];
float progress = (float)[fileTransferData length] / (float)[data length];
NSLog(@"Progresaa value is: %f",progress);
}