We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPM: SnapSDK 2.5.0 (https://github.com/Snapchat/snap-kit-spm) Xcode 16.2 Swift 6.0
Crash Image:
View Info:
struct RootView: View { var body: some View { ZStack{ Button("Snapchat sign in") { Task { do { let provider = SnapchatAuthCoordinator() let params = try await provider.performSignIn() //throw SignInWithError } catch { print("Error: \(error)") } } } }.onOpenURL { url in print("Received URL: \(url)") if SCSDKLoginClient.application(UIApplication.shared, open: url, options: [:]) { // Snapchat print("snapschat sign") } } } }
Code:
import Foundation import SCSDKLoginKit enum LoginAPI { case auth(params: AuthParams) } extension LoginAPI { struct AuthParams: Codable { var username: String? var password: String? var nickname: String? var headImgFileUrl: String? var authorizationCode: String? var email: String? var authType: String } } @MainActor protocol LoginProvider:Sendable { func performSignIn() async throws -> LoginAPI.AuthParams } final class SnapchatAuthCoordinator: LoginProvider { func performSignIn() async throws -> LoginAPI.AuthParams { try await performSnapchatLogin() return try await fetchUserProfile() } private func performSnapchatLogin() async throws { try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in SCSDKLoginClient.login(from: getRootViewController()) { success, error in if let error = error { continuation.resume(throwing: SignInWithError.failed("Snapchat login failed: \(error.localizedDescription)")) return } guard success else { continuation.resume(throwing: SignInWithError.failed("Snapchat login failed.")) return } continuation.resume(returning: ()) } } } private func fetchUserProfile() async throws -> LoginAPI.AuthParams { try await withCheckedThrowingContinuation { continuation in let builder = SCSDKUserDataQueryBuilder() .withDisplayName() .withBitmojiTwoDAvatarUrl() .withIdToken() .withExternalId() let userDataQuery = builder.build() SCSDKLoginClient.fetchUserData(with: userDataQuery) { userData, error in if let error = error { continuation.resume(throwing: SignInWithError.failed("Fetch user data failed: \(error.localizedDescription)")) return } guard let userInfo = userData else { continuation.resume(throwing: SignInWithError.failed("Fetch user data is nil.")) return } var authParams = LoginAPI.AuthParams(authType: "SNAPCHAT") authParams.password = userInfo.idToken authParams.username = userInfo.externalID authParams.nickname = userInfo.displayName if let bitmojiAvatarUrlString = userInfo.bitmojiTwoDAvatarUrl, !bitmojiAvatarUrlString.isEmpty, let avatarUrl = URL(string: bitmojiAvatarUrlString) { if let avatarPath = URLComponents(url: avatarUrl, resolvingAgainstBaseURL: false)?.path { authParams.headImgFileUrl = avatarPath } } continuation.resume(returning: authParams) } failure: { _, _ in continuation.resume(throwing: SignInWithError.failed("Get user profile failed.")) } } } }
The text was updated successfully, but these errors were encountered:
@driefler @mwestergaardsc
Sorry, something went wrong.
No branches or pull requests
SPM: SnapSDK 2.5.0 (https://github.com/Snapchat/snap-kit-spm)
Xcode 16.2
Swift 6.0
Crash Image:
View Info:
Code:
The text was updated successfully, but these errors were encountered: