I’m using SwiftUI to present the view. Below is the relevant code. When I change it to presenting modally in SwiftUI using sheet or fullScreenCover, it does present.
I didn't even know that was tappable, but when I do it does open GameCenter in app.
public var body: some View {
ZStack {
switch gameKitManager.status {
case .authenticated:
Color.accentColor
.edgesIgnoringSafeArea(sizeClass == .compact ? .top : .all)
.opacity(0.6)
ProgressView()
.scaleEffect(1.5)
GKGameCenterView(dismiss: dismiss)
.edgesIgnoringSafeArea(sizeClass == .compact ? .top : .all)
.opacity(showGameKitCenterView ? 1 : 0)
.onAppear {
withAnimation(.linear(duration: 0.75)){
showGameKitCenterView = true
}
}
case .notAuthenticated(let vc):
GKAuthenticationView(vc: vc)
case .error(let error):
createErrorView(error)
case .none:
authenticateButton()
}
}
.navigationBarHidden(true)
.navigationTitle("Achievements")
}
public struct GKGameCenterView: UIViewControllerRepresentable {
let viewController = GKGameCenterViewController()
let dismiss: ()->Void
public func makeUIViewController(context: Context) -> GKGameCenterViewController {
viewController.gameCenterDelegate = context.coordinator
return viewController
}
public func updateUIViewController(_ uiViewController: GKGameCenterViewController, context: Context) {
}
public func makeCoordinator() -> Coordinator {
return Coordinator(self)
}
@MainActor
public final class Coordinator: NSObject, @preconcurrency GKGameCenterControllerDelegate {
let parent: GKGameCenterView
// MARK: - Initializer
init(_ parent: GKGameCenterView) {
self.parent = parent
}
// MARK: - GKGameCenterControllerDelegate
public func gameCenterViewControllerDidFinish(_ gameCenterViewController: GKGameCenterViewController) {
gameCenterViewController.dismiss(animated: true, completion: nil)
parent.dismiss()
}
}
}
Post
Replies
Boosts
Views
Activity
After digging in a bit more, it appears that the view controller has to be presented via a sheet or full screen modal. Previously I was using a switch statement to show the view and that is no longer working. However, this workaround still has some bugs revolving around the view controller so it still doesn't not work for my needs.
Feedback: FB14368686
What is the solution here? I’m running into the same problem.
I’m seeing the same behavior on the released version of Xcode 15.2. It works just fine on the iOS 17.0 simulator, but 17.2 crashes on launch with "EXC_BAD_ACCESS".
usesBottomSafeArea is a new property introduced in iOS 17 to address this. Watch Keep up with the keyboard for more info.
view.keyboardLayoutGuide.usesBottomSafeArea = false
NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: view.topAnchor),
collectionView.bottomAnchor.constraint(equalTo: view.keyboardLayoutGuide.topAnchor),
collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
I have also not been able to get AppIntentsPackage working. I’m copying and pasting the example from Apples documentation, but no shortcuts appear in the shortcuts app.
We are having the exact same problem. Only lower iOS 15 physical devices are effected, it causes a crash, and it seems to do with Swift Concurrency. From our testing it appears that async let may be apart of the issue. To solve this problem in the short term, we also had to put out a hot fix to revert back to Xcode 14.2.
Did you ever find a solution?
I’m also having this issue (Instruments 14.0.1). Did you ever find a fix?
I ended up having to create a UICollectionViewCompositionalLayout subclass, but the solution works really well. You can see the complete solution here.
Same issue with me.
You have to add a large delay for @FocusState to work inside of a sheet. Here is a basic example.
enum FocusableField: Hashable {
case email
case password
}
struct ContentView: View {
@State private var show = false
var body: some View {
Button("Show"){
show.toggle()
}
.sheet(isPresented: $show){
SheetView()
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.previewLayout(.sizeThatFits)
}
}
struct SheetView: View{
@State private var email = ""
@State private var password = ""
@FocusState private var focus: FocusableField?
var body: some View{
NavigationView {
Form {
TextField("email", text: $email, prompt: Text("email"))
.focused($focus, equals: .email)
SecureField("password", text: $password, prompt: Text("password"))
.focused($focus, equals: .password)
}
.navigationTitle("Sign in")
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
focus = .email
}
}
}
}
}
As thisisnotmikey said, you can check the size of the data and see if its 42 bytes, however this also doesn't work because anytime you use the eraser, it adds to the data size. So even if you have a blank canvas and only use the erase, the data size will ballon.
canvasView.drawing.strokes.isEmpty seems to work well. So does canvasView == CGRect(origin: CGPoint(x: CGFloat.infinity, y: CGFloat.infinity), size: .zero).
I've been having this issue to an I found that changing from this
struct Test_Previews: PreviewProvider {
static var previews: some View {
Test()
.environment(\.managedObjectContext, CoreDataManager.shared.context)
}
}
to this has been the solution for me. No idea why this works, but it does.
struct Test_Previews: PreviewProvider {
static var previews: some View {
let context = CoreDataManager.shared.context
return Test()
.environment(\.managedObjectContext, context)
}
}