Social Integration
Share content using the system share sheet:
let text = "Check out this awesome app!"
let image = UIImage(named: "screenshot")
let url = URL(string: "https://apps.apple.com/app/id12345")
let activityVC = UIActivityViewController(
activityItems: [text, image, url].compactMap { $0 },
applicationActivities: nil)
// For iPad (required for popover)
activityVC.popoverPresentationController?.barButtonItem = shareButton
present(activityVC, animated: true)
Apple's privacy-focused authentication service:
import AuthenticationServices
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
let controller = ASAuthorizationController(authorizationRequests: [request])
controller.delegate = self
controller.presentationContextProvider = self
controller.performRequests()
// Delegate
func authorizationController(controller: ASAuthorizationController,
didCompleteWithAuthorization authorization: ASAuthorization) {
if let credential = authorization.credential as? ASAuthorizationAppleIDCredential {
let userId = credential.user
let fullName = credential.fullName
let email = credential.email
// Create user session
}
}
Use the native share sheet for social platforms. For deeper integration, use each platform's SDK:
// Twitter (X) URL scheme
if let url = URL(string: "twitter://post?message=Hello") {
UIApplication.shared.open(url)
}
// Facebook URL scheme
if let url = URL(string: "fb://sharer?u=https://example.com") {
UIApplication.shared.open(url)
}
// Social framework (deprecated - use UIActivityViewController)
// Modern approach: deep links or platform SDKs
Integrate multiple social login providers via Firebase:
import FirebaseAuth
import GoogleSignIn
// Google sign-in
let config = GIDConfiguration(clientID: FirebaseApp.app()?.options.clientID ?? "")
GIDSignIn.sharedInstance.configuration = config
GIDSignIn.sharedInstance.signIn(withPresenting: self) {
result, error in
guard let result = result else { return }
let credential = GoogleAuthProvider.credential(
withIDToken: result.user.idToken?.tokenString ?? "",
accessToken: result.user.accessToken.tokenString)
Auth.auth().signIn(with: credential) { authResult, error in
// Signed in with Firebase
}
}