0

I'm using GKPeerPickerController and GKSession classes and I'm trying to send rather large amount of data (appr 20 mb, images). The problem is that when I send more then, say 10 megabytes the appropriate delegate method of the receiver (- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context;) simply does not getting called. Is there some size restrictions? There is no completion handlers or errors returned. The data is sent to nowhere...I have another question also - is it possible to notify the sender that the data is received? (So that I can send queued packages). Thanks in advance!

Added This method forms a dictionary with objects which I want to send

- (void)sendQuiz:(id<BlitzModelQuizProtocol>)quiz {
    if ([quiz.backgroundType intValue] == BackgroundTypeUser) {
        NSMutableDictionary * background = [NSMutableDictionary new];
        NSString * filePath = [[BUIFileManager sharedInstance] filePathWithFileName:quiz.backgroundPath];
        NSData * imageData = [NSData dataWithContentsOfFile:filePath];
        [background setObject:imageData forKey:kQuizBackgroundImage];
        [background setObject:quiz.backgroundPath forKey:kQuizBackgroundName];
        [self.objectsToSend setObject:background forKey:kQuizBackground];
    }
    for (id<BlitzModelQuestionProtocol>question in quiz.questions) {
        // Improve this logic when answers become > 1
        if ([question.smileyType intValue] == SmileyTypeCustom) {
            NSMutableArray * customSmiles = [NSMutableArray new];
            for (id<BlitzModelAnswerProtocol>answer in question.answers) {
                NSLog(@"smiley is: %@", answer.smiley);
                NSMutableDictionary * smiles = [NSMutableDictionary new];
                NSString * filePath = [[BUIFileManager sharedInstance] filePathWithFileName:answer.smiley];
                NSData * imageData = [NSData dataWithContentsOfFile:filePath];
                [smiles setObject:answer.smiley forKey:kSmileName];
                [smiles setObject:imageData forKey:kSmileImage];
                [customSmiles addObject:smiles];
            }
            [self.objectsToSend setObject:customSmiles forKey:kCustomSmiles];
        }
    }
    NSArray * statistics = [self statisticsForQuizId:quiz.objectId];
    if ([statistics count] > 0) {
        NSMutableArray * blitzStatistics = [NSMutableArray new];
        for (id<BlitzModelStatisticProtocol>stat in statistics) {
            BlitzStatistic * statistic = [[BlitzStatistic alloc] initWithObject:stat];
            [blitzStatistics addObject:statistic];
        }
        [self.objectsToSend setObject:blitzStatistics forKey:kStatiscticObjects];
    }
    else {
        BlitzQuiz * quizModelObject = [[BlitzQuiz alloc] initWithObject:quiz];
        [self.objectsToSend setObject:quizModelObject forKey:kQuizObject];
    }
    NSData * data = [NSKeyedArchiver archivedDataWithRootObject:self.objectsToSend];
    [self sendDataToPeers:data];
}

This is my sendData method:

- (void) sendDataToPeers:(NSData *) data {
    NSString * title;
    if (self.currentSession) {
        NSError * error = nil;
        if ([self.currentSession sendDataToAllPeers:data
                                        withDataMode:GKSendDataReliable
                                               error:&error]) {
            NSLog(@"quiz sent");
        }
        else {
            NSLog(@"error desc is: %@", [error localizedDescription]);
        }

    }
}

The method - (BOOL)sendDataToAllPeers:(NSData *)data withDataMode:(GKSendDataMode)mode error:(NSError **)error returns YES with no error (it's nil). What am I doing wrong?

Added

Sometimes the data is received successfully though sendData still returns NO without any error. Neither of delegate methods that handle error is getting called.

Stas
  • 9,925
  • 9
  • 42
  • 77
  • `sendData:toPeers:withDataMode:error:` returns a `BOOL` to indicate whether or not the data was successfully queued for transmission. What is the value of this in your app? – neilco Oct 26 '13 at 10:40
  • it is yes with no error returned – Stas Oct 26 '13 at 11:08
  • In the receiver, did you set `setDataReceiveHandler:withContext:` to `self`? In either server or client, did either `session:didFailWithError:` or `session:connectionWithPeerFailed:withError:` get called? Show us some of your code. – neilco Oct 26 '13 at 12:32
  • Sure, the code is currently unreachable, will post it in monday, thanks for your time! – Stas Oct 26 '13 at 15:11

0 Answers0