My game has two UIViewControllers
. The first one finds a match with the matchmakerViewController(didFindMatch:)
method. Once the match is found, the player is taken to the second one.
The GKVoiceChat
should be active in the second one. Though, I am currently setting it up in the first UIViewController
. Is this the right approach? I can't find any way to do it in the second UIViewController
, as I can't create a GKMatch
variable wherever I want.
To add a GKVoiceChat
, I use the following code:
func matchmakerViewController(viewController: GKMatchmakerViewController!,
didFindMatch match: GKMatch!) {
println("I found a match.")
// Checking if the device has a microphone
if !GKVoiceChat.isVoIPAllowed() {
return
}
// Creation of an audio session
var audioSession:AVAudioSession = AVAudioSession.sharedInstance()
audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
audioSession.setActive(true, error: nil)
// Setting up a voice channel
let allChannel = match.voiceChatWithName("allChannel")
allChannel.active = true
allChannel.volume = 1.0
allChannel.start()
// Redirect the player to a new UIViewController
let storyboard = UIStoryboard(name: "Universal", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ViewController") as UIViewController
self.dismissViewControllerAnimated(true, completion: nil)
self.presentViewController(vc, animated: true, completion: nil)
}
What works
- The game successfully asks permission to use the microphone;
- The code compiles just fine. No crashes or errors occur.
- The game successfully authenticates the user, and redirect him/her to the second
UIViewController
What doesn't
- No voice is transmitted I don't hear any sounds. Why is that happening?