0

我正在使用 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 而没有任何错误,但数据会成功接收。处理错误的委托方法都没有被调用。

4

0 回答 0