While working with GameKit for some time, I found that there is a limit of about 90 thousand to “send”, so if you are more than 90k, you will have to break it. Here's how I suggest you figure it out:
1st - send your file name
NSData* fileNameData = [fileNameStr dataUsingEncoding: NSASCIIStringEncoding];
2nd - Send the number of pieces you are about to send
NSUInteger fiftyK = 51200;
NSUInteger chunkCount = (((NSUInteger)(srcData.length / fiftyK)) + ((srcData.length % fiftyK) == 0 ) ? 0 : 1))
NSString chunkCountStr = [NSString stringWithFormat:@"%d",chunkCount];
NSData* chunkCountData = [chunkCountStr dataUsingEncoding: NSASCIIStringEncoding];
3rd - Break and submit your NSData object to a set of NSObjects less than 50k each (only for safe size)
NSData *dataToSend;
NSRange range = {0, 0};
for(NSUInteger i=0;i<srcData.length;i+=fiftyK){
range = {i,fiftyK};
dataToSend = [srcData subdataWithRange:range];
}
NSUInteger remainder = (srcData.length % fiftyK);
if (remainder != 0){
range = {srcData.length - remainder,remainder};
dataToSend = [srcData subdataWithRange:range];
}
On the receiving side, you will want to do the following:
1st - Get file name
NSString* fileNameStr = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding]
2nd - Get the number of pieces you are going to receive
NSString* chunkCountStr = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding]
NSUInteger chunkCount = [chunkCount intValue];
3rd - Get chunks of data
NSMutableData data = [[NSMutableData alloc]init];
for (NSUInteger i=0; i<chunkCount;i++){
[data appendData:receivedData];
}
If everything worked correctly, now you will have an object fileNameStrcontaining your file name and an object datacontaining the contents of your file.
Hope this helps - AYAL