ios - 如何将此 GKVoiceChat 代码迁移到 Swift?

标签 ios swift game-center

我想将以下创建游戏中心 GKVoiceChat 的代码迁移到 Swift 中:

GKMatch* match;
GKVoiceChat *teamChannel = [[match voiceChatWithName:@"redTeam"] retain];
GKVoiceChat *allChannel = [[match voiceChatWithName:@"allPlayers"] retain];

我怀疑 Swift 代码看起来像这样:

var match: GKMatch!
func voiceChatWithName(name: String!) -> GKVoiceChat! {
    return nil
}

但即使我搜索了文档,我也不清楚它在 Swift 中是如何工作的。如何将上面的代码迁移到 Swift?

最佳答案

因此,在您的 GKMatchmakerViewControllerDelegate 方法中,您应该能够执行如下操作:

func matchmakerViewController(_ viewController: GKMatchmakerViewController!,
                      didFindMatch match: GKMatch!) {

    let teamChannel = match.voiceChatWithName("redTeam")
    let allChannel = match.voiceChatWithName("allPlayers")

    // use the channels above
}

关于ios - 如何将此 GKVoiceChat 代码迁移到 Swift?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28927180/

相关文章:

ios - 过滤嵌套数组和字典

iphone - Present Modal ViewController 需要 5 秒才能调出模态

swift - 在 Swift Struct 中删除NotificationCenter Observer的最佳位置

swift - 快速放置一个与屏幕相关的对象

ios - 游戏中心和我自己的服务器

ios - UITabBar 屏幕顶部

iOS UIPageControl 改变位置

ios - swift 4、设置textField localizedString占位符颜色

swift - GameCenter 分数未发布到排行榜

IOS游戏中心成就上传