Post

Replies

Boosts

Views

Activity

Reply to GKGameCenterViewController Is Blank On iOS 18
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() } } }
1w
Reply to GKGameCenterViewController Is Blank On iOS 18
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.
2w
Reply to How to ignore the safe area when using keyboardLayoutGuide
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) ])
Aug ’23
Reply to FocusState SwiftUI not working
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                 }             }         }     } }
Nov ’21
Reply to PKDrawing() == PKDrawing() returns false
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).
Apr ’21
Reply to Preview Crashes when using @FetchRequest
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)     } }
Oct ’20