我可以通过蓝牙一次发送多少个字节数据?

时间:2013-10-26 10:12:38

标签: ios objective-c bluetooth gksession gkpeerpickercontroller

我正在使用GKPeerPickerController和GKSession类,我正在尝试发送相当大量的数据(大约20 mb,图像)。问题是当我发送更多信息时,比如10兆字节,接收方(- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context;)的适当委托方法根本就不会被调用。是否有一些尺寸限制?没有完成处理程序或返回错误。数据被发送到任何地方......我还有另一个问题 - 是否可以通知发件人数据已收到? (这样我就可以发送排队的包)。提前谢谢!

此方法形成一个包含我想要发送的对象的字典

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

这是我的sendData方法:

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

    }
}

方法- (BOOL)sendDataToAllPeers:(NSData *)data withDataMode:(GKSendDataMode)mode error:(NSError **)error返回YES没有错误(它是零)。我做错了什么?

有时数据收到成功虽然sendData仍然返回NO而没有任何错误。调用处理错误的委托方法都没有被调用。

0 个答案:

没有答案