[ad_1]
I wish to create my very own SignInWithAppleButton with my very own design, following the rules after all.
I’m having bother translating the startSignInWithAppleFlow perform from Swift to SwiftUI.
struct ContentView: View {
var physique: some View {
...
AuthButton(title: "Join with Apple", iconName: "appleIcon") {
authViewModel.signInWithApple()
}
...
}
}
struct AuthButton: View {
let title: String
let iconName: String
let motion: () -> Void
var physique: some View {
Button {
motion()
} label: {
RoundedRectangle(cornerRadius: 16)
.fill(.clear)
.body(peak: 80)
.overlay(
Textual content(title)
.font(.regular16)
.foregroundColor(.black)
)
.overlay(
HStack {
HorizontalSpacer(width: 32)
Picture(iconName)
.resizable()
.body(width: 30, peak: 30, alignment: .heart)
Spacer()
}
)
}
.buttonStyle(AuthButtonStyle())
}
}
class AuthenticationViewModel: ObservableObject {
func signInWithApple() {
Unclear what ought to be right here!
}
personal func randomNonceString(size: Int = 32) -> String {
precondition(size > 0)
let charset: [Character] =
Array("0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._")
var outcome = ""
var remainingLength = size
whereas 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.depend {
outcome.append(charset[Int(random)])
remainingLength -= 1
}
}
}
return outcome
}
personal func sha256(_ enter: String) -> String {
let inputData = Knowledge(enter.utf8)
let hashedData = SHA256.hash(knowledge: inputData)
let hashString = hashedData.compactMap {
String(format: "%02x", $0)
}.joined()
return hashString
}
}
[ad_2]
