To run the example project, clone the repo, and run pod install
from the Example directory first.
SocialLogins is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'SocialLogins'
Note: Use SocialLogins shared instance in AppDelegate & SceneDelegate
Set in AppDelegate.swift
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Required if you're using GoogleSignIn, otherwise no need to call.
SocialLogins.shared.configure(clientID: "")
let _ = SocialLogins.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
}
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any] = [:]
) -> Bool {
return SocialLogins.shared.application(
app,
open: url,
options: options
)
}
Set in SceneDelegate.swift
(if SceneDelegate exist, otherwise no need to create)
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
SocialLogins.shared.scene(
scene,
openURLContexts: openURLContexts
)
}
If you implement methods above, no need to re implement them while following Google & Facebook instructions. (Just configure URL Schemes & Info.plist)
-
Apple
Enable Sign in with Apple from Project's settings, Signing & Capabilities -
Google
Google Login SDK integration
- Make sure to add URL scheme, TARGETS > Info > URL Types > + (Add)
- Facebook
Facebook Login SDK integration Make sure to follow link;
You'll need to create an app from facebook developer & communicate with your project. Modify Info.plist & URL Scheme
- Apple
You can create your own LoginViewModel
import SocialLogins
import FirebaseAuth // Imagine we'll send provided info to Firebase
class MyLoginViewModel: SocialLogins.LoginViewModel {
override init() {
super.init()
}
override func completeSignIn(with authResult: SocialLogins.AuthResult) {
super.completeSignIn(with: authResult)
// Here you may send credentials to different backend, instead Firebase.
func signInToFirebase(with credential: AuthCredential) {
Auth.auth().signIn(with: credential) { (result, error) in
if let user = result?.user {
print("**** \(self.selectedSignInMethod.rawValue) sign in succeeded")
self.signInSucceeded = true
}
}
}
switch selectedSignInMethod {
case .apple:
let credential = OAuthProvider.credential(
withProviderID: "apple.com",
idToken: authResult.idToken!,
rawNonce: authResult.rawNonce
)
signInToFirebase(with: credential)
case .google:
let credential = GoogleAuthProvider.credential(
withIDToken: authResult.idToken!,
accessToken: authResult.accessToken!
)
signInToFirebase(with: credential)
case .facebook:
let credential = FacebookAuthProvider.credential(
withAccessToken: authResult.accessToken!
)
signInToFirebase(with: credential)
case .none: break
}
}
}
And create your UI elements (buttons), when they tapped, just trigger related provider;
Just trigger LoginViewModel.startSignInProcess(with: SignInMethod)
AppleSignInButton()
.frame(height: 50)
.border(Color.black, width: 1)
.padding()
.onTapGesture{ loginViewModel.startSignInProcess(with: .apple) }
// Any button that might contain Google's logo and some text
GoogleSignInButton()
.frame(height: 50)
.border(Color.black, width: 1)
.padding()
.onTapGesture { loginViewModel.startSignInProcess(with: .google) }
// Any button that might contain Facebook's logo and some text
FacebookSignInButton()
.frame(height: 50)
.border(Color.black, width: 1)
.padding()
.onTapGesture{ loginViewModel.startSignInProcess(with: .facebook) }
eneskaraosman, eneskaraosman53@gmail.com
SocialLogins is available under the MIT license. See the LICENSE file for more info.