Post

Replies

Boosts

Views

Activity

SwiftUI Map keeps overriding appearance of ToolBar / NavigationBar
When adding a Map using the MapKit this changes the appearance of the TabBar appearance, specifically gives the toolbar a translucent background with a shadow; the default iOS style. I have tried adding the following modifier to the Map .toolbarBackground(Color("White"), for: .navigationBar) But the navigation toolbar still has a shadow, and the TabBar has the default translucent background colour with shadow. Root init() { // this is not the same as manipulating the proxy directly let appearance = UINavigationBarAppearance() // this overrides everything you have set up earlier. appearance.configureWithTransparentBackground() appearance.shadowColor = .clear //In the following two lines you make sure that you apply the style for good UINavigationBar.appearance().scrollEdgeAppearance = appearance UINavigationBar.appearance().standardAppearance = appearance UITabBar.appearance().barTintColor = UIColor.white) UITabBar.appearance().backgroundColor = UIColor.white) UITabBar.appearance().shadowImage = UIImage() UITabBar.appearance().backgroundImage = UIImage() UINavigationBar.appearance().isTranslucent = false UIToolbar.appearance().backgroundColor = UIColor.white) UIToolbar.appearance().isTranslucent = false UIToolbar.appearance().setShadowImage(UIImage(), forToolbarPosition: .any) } struct MainView: View { var body: some View { TabView { ContentView() .tabItem { Label("Menu", systemImage: "list.dash") } } } } The Tabbar has a solid white colour with no shadow, as well as navigation bars. Content View struct ContentView: View { var body: some View { NavigationStack() { NavigationLink(destination: MapView()) { Text("Hello, World!") } } .navigationTitle("Content") } } MapView struct MapView: View { @State private var region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 51.507222, longitude: -0.1275), span: MKCoordinateSpan(latitudeDelta: 0.5, longitudeDelta: 0.5)) var body: some View { Map(coordinateRegion: $region) .mapControlVisibility(.hidden) .allowsHitTesting(false) .frame(maxWidth: .infinity) .frame(height: 414) .clipped() } } I have looked through the documentation but could not find anything. https://developer.apple.com/documentation/mapkit/map
0
0
105
3w
Sign In with Apple: Attempting to present ASAuthorizationController from a SwiftUI view not in a hierarchy
I have a SwiftUI app where I can sign in via Apple Sign In using Firebase Auth. This works completely fine on iPad and iPhone. However when when running the app via catalyst on Mac, using Apple Sign In I get a crash with the following log. _AuthenticationServices_SwiftUI/SignInWithAppleButton.swift:303: Fatal error: Attempting to present ASAuthorizationController from a SwiftUI view not in a hierarchy. This should not be possible, please file feedback. 2022-07-13 19:31:29.368989+0100 appname[93200:13915263] _AuthenticationServices_SwiftUI/SignInWithAppleButton.swift:303: Fatal error: Attempting to present ASAuthorizationController from a SwiftUI view not in a hierarchy. This should not be possible, please file feedback. (lldb) I am not sure what is wrong, I have checked Apple Documentation and am struggling to find a fix. Apple Sign In Object: import SwiftUI import AuthenticationServices import CryptoKit @EnvironmentObject var store: Store struct SignInWithAppleButtonView: View { //Hashing function using CryptoKit private func sha256(_ input: String) -> String { let inputData = Data(input.utf8) let hashedData = SHA256.hash(data: inputData) let hashString = hashedData.compactMap { return String(format: "%02x", $0) }.joined() return hashString } // from https://firebase.google.com/docs/auth/ios/apple private func randomNonceString(length: Int = 32) -> String { precondition(length > 0) let charset: Array<Character> = Array("0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._") var result = "" var remainingLength = length while remainingLength > 0 { let randoms: [UInt8] = (0 ..< 16).map { _ in var random: UInt8 = 0 let errorCode = SecRandomCopyBytes(kSecRandomDefault, 1, &random) if errorCode != errSecSuccess { fatalError("Unable to generate nonce. SecRandomCopyBytes failed with OSStatus \(errorCode)") } return random } randoms.forEach { random in if remainingLength == 0 { return } if random < charset.count { result.append(charset[Int(random)]) remainingLength -= 1 } } } return result } @State var currentNonce:String? var body: some View { SignInWithAppleButton(.signIn) { request in // You can change them if needed. let nonce = randomNonceString() currentNonce = nonce request.requestedScopes = [.fullName, .email] request.nonce = sha256(nonce) } onCompletion: { result in // Switch result switch result { // Auth Success case .success(let authResults): default: break } case .failure(let error): print("failure", error) } } .frame(maxWidth: .infinity) } Login import SwiftUI import AuthenticationServices import CryptoKit struct login: View { @EnvironmentObject var store: Store var body: some View { GeometryReader { geometry in ZStack(alignment: .bottom) { VStack(alignment: .center, spacing: 20) { SignInWithAppleButtonView() .signInWithAppleButtonStyle(.black) .environmentObject(store) } } } } } Handler class Store : ObservableObject { func signInWithAppleHandler(credential: OAuthCredential) { Auth.auth().signIn(with: credential) { (authResult, error) in if (error != nil) { // Error. If error.code == .MissingOrInvalidNonce, make sure // you're sending the SHA256-hashed nonce as a hex string with // your request to Apple. print(error?.localizedDescription as Any) return } print("Signed in") if let user = authResult?.user { // Fetch profile let db = Firestore.firestore() db.collection("users").document(user.uid).getDocument { [self] (document, error) in if let document = document, document.exists { //User exists now save that to current user _ = document.data().map(String.init(describing:)) ?? "nil" do { self.profile = try document.data(as: Profile.self) } catch { print("There was an error getting decoding Profile") } if self.profile != nil { self.userAuthState = .signedIn self.isNewUser = self.profile!.newUser self.loadProfileImageFromFirebase(uid: profile!.uid) } } else { // create profile firestoreManager.createProfile(uid: user.uid, email: user.email ?? "") fetchProfile(uid: user.uid) } } } } } } Apple Documentation: https://developer.apple.com/documentation/authenticationservices/signinwithapplebutton Firebase Documentation: https://firebase.google.com/docs/auth/ios/apple
1
3
1.1k
Jul ’22
Sidebar inset spacing changes on rotation and reload - SwiftUI
I have a SwiftUI app that uses a sidebar on iPad. I can not figure out why the edge spacing does not apply, however when I force close the app and reopen it appears normal. Problem: When user first signs in rotates device collapses sidebar and reopens) The problem goes away when force quitting the app and reloading when user is signed in. ContentView struct ContentView: View { var body: some View { #if os(iOS) if horizontalSizeClass == .compact { AppTabView() .environmentObject(store) .environmentObject(quickActionSettings) } else { AppSideNavView() .environmentObject(store) } #else AppSideNavView() .environmentObject(store) #endif } } AppSideNavView (For iPad) struct AppSideNavView: View { @EnvironmentObject var store: Store var body: some View { if store.userAuthState == .signedOut { LoginView() } else if store.userAuthState == .signedIn { AppSidebarNavigation() .environmentObject(store) } else { LoginView() } } } Sidebar struct AppSidebarNavigation: View { enum NavigationItem { case home case expenses } @EnvironmentObject var store: Store @State private var selection: NavigationItem? = .home var body: some View { NavigationView { sidebar .navigationTitle("") .navigationBarTitleDisplayMode(.inline) .navigationBarHidden(true) HomesView() .environmentObject(store) } .navigationViewStyle(DoubleColumnNavigationViewStyle()) } } extension AppSidebarNavigation { var sidebar: some View { List(selection: $selection) { Group { NavigationLink(destination: HomesView() .environmentObject(store), tag: NavigationItem.home, selection: $selection) { Label("Homes", systemImage: "house") .modifier(navText()) } .tag(NavigationItem.home) NavigationLink(destination: ExpensesView() .environmentObject(store) .navigationBarTitleDisplayMode(.large), tag: NavigationItem.expenses, selection: $selection) { Label("Expenses", systemImage: "arrow.right.arrow.left") .modifier(navText()) } .tag(NavigationItem.expenses) } } .listRowBackground(Color("White")) .background(Color("White")) .listStyle(.sidebar) } }
1
0
1.2k
Jun ’22
Associated Domains - URL not opening app
I am trying to redirect the user to the installed app when visiting *www.example.com/success* as well as show a banner when visiting the homepage. With my current implantation the url DOES NOT redirect and open the app and neither does the website display a banner. I am following the documentation found here https://developer.apple.com/documentation/safariservices/supporting_associated_domains My website is a simple create-react-app with a homepage hosted with Firebase. I have done the following: 1) Add Associated Domains to Signing and Capabilities - *applinks:website.com/success* 2) Add apple-app-site-association file to /public/ 3) Amend firebase.json file 4) Link to files in index.html What I am using to validate: https://search.developer.apple.com/appsearch-validation-tool Testing by adding www.example.com/app link to notes and opening, It always opens in safari. I Have also tried reinstalling the app and restarting the phone. Apple API Validation I have uploaded a new app version with associated domains to the store and Link To Application has Passed with link www.example.com/. When visiting www.example.com/apple-app-site-association { "activitycontinuation": { "apps": [ "team.com.example.com" ] }, "applinks": { "apps": [], "details": [ { "appID": "team.com.example.com", "paths": [ "/", "/*", "/success", "/success/*",] }, "webcredentials": { "apps": [ "team.com.example.com" ] } } apple-app-site-association } Index.html meta name="App" content="app-id=***, app-argument=https://apps.apple.com/US/app/APP/idXXX, affiliate- data=optionalAffiliateData" Firebase.json } https://stackoverflow.com/questions/66871656/how-to-setup-associated-domains-universal-links
0
2
4.0k
Apr ’21
Adjusting view for Keyboard Height on iPad - SwiftUI
When adjusting my view for the Keyboard Height there is additional space between the software keyboard and the view I am trying to move up using the height. It seems the space is the same space between the sheet and the bottom of the screen. I have no issues on iPhone, and no issues if the view is part of a NavigationView, but only on iPad and when presented via a .sheet. The size of the space changes on iPad device and if it is in landscape. The View is a ZStack with a ScrollView and a TextField. ChatView } SendMessage } KeyboardAwareModifier } Alternative attempt .offset(y: -keyboard.currentHeight) KeyboardResponder } Also tried suggestions from other posts, most of which are included in this post: https://stackoverflow.com/questions/57746006/how-to-get-the-keyboard-height-on-multiple-screens-with-swiftui-and-move-the-but Question with screenshots: https://stackoverflow.com/questions/66309208/adjusting-view-for-keyboard-height-on-ipad-not-working-swiftui
0
0
2.6k
Feb ’21