GameKit Access Point causes camera background image in ARKit to be black in iOS 18 beta only

I have an AR game using ARKit with SceneKit that works just fine in iOS 17. In the iOS 18 betas, the AR background image shows black instead of showing the real world. As a result there's no tracking and obviously the whole game is useless.
I narrowed down the issue to showing the Game Center Access Point.

My app has ViewController 1 (VC1) showing the main menu and that's where I want to show the GC Access Point. From there you open VC2 which shows a list of levels. Selecting any level will open VC3 which has the ARScene.

Following is the code I use to start Game Center in VC1:

GKLocalPlayer.local.authenticateHandler = { gcAuthVC, error in
            let isGameCenterReady = (gcAuthVC == nil) && (error == nil)
            
            if let viewController = gcAuthVC {
                self.present (viewController, animated: true, completion: nil)
            }
            
            if error != nil {
                print(error?.localizedDescription ?? "")
            }
            
            if isGameCenterReady {
                GKAccessPoint.shared.location = .topLeading
                GKAccessPoint.shared.showHighlights = true
                GKAccessPoint.shared.isActive = true
            }
        }

When switching to VC2 I run GKAccessPoint.shared.isActive = false so that the Access Point will no longer show in any of the following VCs. I tried running it in VC1, VC2, and again in VC3 - it doesn't change anything. Once I reach VC3, the background is black.

If in VC1 I don't run GKAccessPoint.shared.isActive = true, so I don't activate the access point, the behavior is as follows:

  • If I wait until after the Game Center login animation completes and closes on its own and then I proceed to VC2 and VC3, the camera image will show correctly
  • If I quickly move to VC2 before the Game Center login animation has completed, so my code will close it by setting active = false, and then I continue to VC3, I will see the black background problem.

So it does look like activating the access point and then de-activating it causes the issue. BTW, if I activate the access point and leave it on in all VCs, the same black background issue persists.

Other than that, when I'm in VC3 with the black background and I switch to another app (so my game moves to the background), when it returns to the foreground, the camera suddenly shows the real world correctly!
I tried to manually reset the AR session by pausing and restarting it, but that didn't change anything. Also, when I check with the debugger, it looks like when the app comes back to the foreground it also doesn't run the session start code.
But something does seem to reset itself so I wonder what that is. Maybe I could trigger the same manually in my cdoe???

I repeat that everything works just fine in iOS 17 and below. This problem only started with the iOS 18 beta (currently on beta 5, but it started in some of the previous betas as well).
So could this be a bug in iOS 18?

As a workaround I could check the iOS version and if it's iOS18 not activate the access point, hoping that the user will not jump to VC2 too quickly, and show my own button which will open Game Center. But I'd rather give the users the full experience with their own avatar and the highlights showing up. Plus, certainly some users will move quickly to VC2 and that will be an awful experience.

Any help would be greatly appreciated. Thanks!

Please reproduce the issue, then file an issue on feedbackassistant.apple.com with an attached sysdiagnose. That will help us investigate the issue. If you provide the FB number here, we can be sure to follow-up.

Thanks! I reproduced the issue and filed FB14697134

In the meantime I realized that having app going to background then back to the foreground causes Game Center to re-login on its own so probably the ARSCNView gets to work properly and then Game Center kicks in and that's why it's working in this case.
To test this out, I moved the whole GameKit user authentication code from VC1 to VC3 and that way it also works fine (but I obviously don't want the Game Center graphics in the middle of my gameplay).

So this issue only happens if the access point is activated before the ARSCNView is activated.

Hello,

I am experiencing the same issue. I have a game that uses the camera, and when the user plays quickly while the Game Center "Hello" animation is active, the camera won't start or will freeze. It only resumes functioning once the Game Center animation has completed.

Below is a straightforward sample code to reproduce and test the issue:

//
//  ViewController.swift
//  ShowCameraIssue
//
//  Created by Dylan Absil on 02/12/2024.
//

import UIKit
import AVFoundation
import GameKit

class ViewController: UIViewController {
    private var captureSession: AVCaptureSession!
    private var previewLayer: AVCaptureVideoPreviewLayer!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        handleCameraAuthorization()
    }
    
    func beginTest() {
        self.setupCameraPreview()
        
        DispatchQueue.global(qos: .userInitiated).async {
            self.captureSession.startRunning()
        }
        DispatchQueue.main.async {
            self.gameCenterLogin()
        }
    }
    
    private func handleCameraAuthorization() {
        switch AVCaptureDevice.authorizationStatus(for: .video) {
        case .authorized:
            beginTest()
        case .notDetermined:
            AVCaptureDevice.requestAccess(for: .video) { granted in
                if granted {
                    self.beginTest()
                }
            }
        default:
            print("Camera access denied or restricted.")
        }
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        previewLayer.frame = self.view.bounds
    }
}

extension ViewController { // CAMERA
    private func setupCameraPreview() {
        captureSession = AVCaptureSession()
        captureSession.sessionPreset = .high
        
        guard let frontCamera = AVCaptureDevice.default(.builtInWideAngleCamera,
                                                        for: .video,
                                                        position: .front) else {
            return
        }
        
        do {
            let input = try AVCaptureDeviceInput(device: frontCamera)
            if captureSession.canAddInput(input) {
                captureSession.addInput(input)
            }
        } catch {
            return
        }
        
        previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
        previewLayer.videoGravity = .resizeAspectFill
        previewLayer.frame = self.view.bounds
        
        self.view.layer.addSublayer(previewLayer)
        
    }
}

extension ViewController { // GAME CENTER
    func gameCenterLogin() {
        GKLocalPlayer.local.authenticateHandler = { viewController, error in
            if let err = error {
                print(err)
            }
            else if let controller = viewController {
                self.present(controller, animated: true, completion: nil)
            }
        }
    }
}

Any updates on this? Wasted several hours trying to figure out why my code suddenly doesn't work before running across this post. I had been using ARView with RealityKit in non-AR and on simulator for several weeks with no issue. Flipped it back to use AR again on device and suddenly the camera was black. I tend to be a little behind on updates while grinding through a project. But this had all been working as of a few months ago. An update to the latest version of XCode today did not fix it. I already had GKAcceessPoint.shared.isActive set to false before moving to that VC. But if I avoid GameCenter altogether, the camera works.

@Bill3D and @dylanabsil, as I updated above, I opened FB14697134 for this issue. Apple initially replied that I should update 3rd parties (without explaining which ones) and then looking at my logs said that this happened because something I did in my code and they closed the feedback.
But I showed that I had everything updated and that they got the timing wrong in my logs and they re-opened the feedback. But it's been open like this for quite some time without any update. In another feedback I opened for another issue I got an update that a potential fix was identified for a future update; I didn't get anything like that for this feedback so right now it doesn't look very promising.
I therefore suggest that you both also open a feedback on this issue so that Apple engineers will understand that there is a demand for this to be fixed. If you'll look at my feedback you'll see that it says: "Recent Similar Reports: Less than 10".
So let's make sure they understand that we need a fix.
Also, @Bill3D, your issue is with RealityKit and mine was with ARKit so that means the issue is wider than what I originally reported so you should mention that as well.
Let's hope for the best.
Thanks.

Thank you for the update and for working on this issue. RealityKit is like SceneKit, both are 3D frameworks that use ARKit as the AR framework. So this may actually help isolate the issue to the ARKit/Game Center interaction. Plus I swear it was all working for me months ago. However I also just realize this is breaking a SceneKit AR app I already have in the store. Granted, not a very popular one. Still an annoying mess. I'll file the TPS.

GameKit Access Point causes camera background image in ARKit to be black in iOS 18 beta only
 
 
Q