我有点晚了,但我会三重检查您用于创建会话的容器名称。
我在 xCode 中启用了所有三个选项:键值存储、iCloud 文档和 CloudKit。
我不使用 iCloud 驱动器。
每次我发送邀请时,以下代码都会成功创建一个新会话。它打印新会话,然后遍历该容器 ID 的所有现有会话。
-(void)turnBasedMatchmakerViewController:(GKTurnBasedMatchmakerViewController *)viewController didFindMatch:(GKTurnBasedMatch *)match
{
[self dismissViewControllerAnimated:YES completion:nil];
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
NSString *iCloudContainerName = [@"iCloud." stringByAppendingString: bundleIdentifier];
[GKGameSession createSessionInContainer:iCloudContainerName
withTitle:@"test"
maxConnectedPlayers:4
completionHandler:^(GKGameSession * _Nullable session, NSError * _Nullable error)
{
NSLog(@"(1) Session: %@, Error: %@", session.identifier, [error description]);
[GKGameSession loadSessionsInContainer:iCloudContainerName
completionHandler:^(NSArray<GKGameSession *> * _Nullable sessions, NSError * _Nullable error)
{
for (GKGameSession *session in sessions)
{
NSLog(@"(2) Session: %@, Error: %@", session.identifier, [error description]);
}
NSLog(@"-----");
}];
}];
}