SwiftGoogleSignIn is an open-source package which uses Google Sign-In for iOS and macOS and can be used to make sign in. Here you can find an example of using this package.
iOS 15, Swift 5.7
import SwiftGoogleSignIn
First of all you need approved scope permission. There are sensitive scopes for Google APIs to have ability to work properly Make sure they are presented in your app. Then send request on verification. After the verification provide them for the initializa method:
let googleAPIscopes: [String] = ["https://www.googleapis.com/auth/youtube",
"https://www.googleapis.com/auth/youtube.readonly",
"https://www.googleapis.com/auth/youtube.force-ssl"]
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SwiftGoogleSignIn.API.initialize(googleAPIscopes)
}
Handle open URL:
func application(_ application: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
return SwiftGoogleSignIn.API.openUrl(url)
}
import SwiftGoogleSignIn
struct LogInContentView: View {
var body: some View {
...
SignInButton()
...
}
}
SwiftGoogleSignIn.API
.publisher
.receive(on: RunLoop.main)
.sink(
receiveCompletion: { result in
if case let .failure(error) = result {
// parse the error
}},
receiveValue: { session in
if session.isConnected {
// success connect
} else {
// failed connect
}
}
)
func initialize(_ scopePermissions: [String]?)
/// The Client has to set up UIViewController for Goggle SignIn UI base view
var presentingViewController: UIViewController? { get set }
/// Google user's connect state publisher
var publisher: AnyPublisher<UserSession, SwiftError> { get }
/// Please use SignInButton view for log in
func logIn()
/// Log out. Handle result via publisher
func logOut()
/// As optional we can send request with scopes
func requestPermissions()
/// The Client has to handle openUrl app delegate event
func openUrl(_ url: URL) -> Bool
link |
Stars: 1 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics