Stas
Stas

Reputation: 9935

How many data in bytes can I send at a time via bluetooth?

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.

Upvotes: 0

Views: 577

Answers (0)

Related Questions