GCControllerDidConnect/GCControllerDidDisconnect notifications don't work in a Playground

The following code does not work in an Xcode Playgrounds or the Swift Playgrounds App on iOS oder macOS. But the same code works when used in an app.

Does anyone know how to get the notifications running in a Playground?

import GameController
import Combine
import SwiftUI
import PlaygroundSupport

PlaygroundPage.current.needsIndefiniteExecution = true

var cancellables = Set<AnyCancellable>()

NotificationCenter.default.publisher(for: NSNotification.Name.GCControllerDidConnect)
.subscribe(on:DispatchQueue.global())
    .print()
    .receive(on: DispatchQueue.main)
    .sink { notification in
        print(notification)
    }.store(in: &cancellables)


let disConnect = NotificationCenter.default.publisher(for: NSNotification.Name.GCControllerDidDisconnect)
    .print()
    .subscribe(on:DispatchQueue.global())
    .receive(on: DispatchQueue.main)
    .sink { value in
        print(value)
    }.store(in: &cancellables)

Hi Schlumpfpapa

I tested your code on iPadOS 15.1, but I am seeing the Connect notification posted when I pair a DualShock 4 with the iPad. Are you still able to reproduce this in Swift Playgrounds on the latest iPadOS?

GCControllerDidConnect/GCControllerDidDisconnect notifications don't work in a Playground
 
 
Q