I hereby claim:
- I am henning-jh on github.
- I am henningh (https://keybase.io/henningh) on keybase.
- I have a public key ASAmRDGCvjc8UVEqP98qf_-JdHy8LLdSl1AQzjusIHO6rwo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
let center = NotificationCenter.default | |
let name = NSNotification.Name.ASAuthorizationAppleIDProviderCredentialRevoked | |
let observer = center.addObserver(forName: name, object: nil, queue: nil) { (notification) in | |
// sign user out | |
// optionally guide them to sign in again | |
} |
let userIdentifier = // get saved userIdentifier - sample app uses Keychain | |
appleIDProvider.getCredentialState(forUserID: userIdentifier) { (credentialState, error) in | |
switch credentialState { | |
case .authorized: | |
// The Apple ID credential is valid. | |
break | |
case .revoked: | |
// The Apple ID credential is revoked. | |
break | |
case .notFound: |
extension MyLoginViewController: ASAuthorizationControllerDelegate { | |
func authorizationController(controller: ASAuthorizationController, | |
didCompleteWithAuthorization authorization: ASAuthorization) { | |
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential { | |
let userIdentifier = appleIDCredential.user | |
let fullName = appleIDCredential.fullName | |
let email = appleIDCredential.email | |
// Now we have the account information. |
extension MyLoginViewController: ASAuthorizationControllerDelegate { | |
func authorizationController(controller: ASAuthorizationController, | |
didCompleteWithError error: Error) { | |
// Handle error. | |
} | |
} |
extension MyLoginViewController: ASAuthorizationControllerPresentationContextProviding { | |
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { | |
return self.view.window! | |
} | |
} |
/// Prompts the user if an existing iCloud Keychain credential or Apple ID credential is found. | |
func performExistingAccountSetupFlows() { | |
// Prepare requests for both Apple ID and password providers. | |
let requests = [ASAuthorizationAppleIDProvider().createRequest(), | |
ASAuthorizationPasswordProvider().createRequest()] | |
// Create an authorization controller with the given requests. | |
let authorizationController = ASAuthorizationController(authorizationRequests: requests) | |
authorizationController.delegate = self | |
authorizationController.presentationContextProvider = self |
@objc | |
func handleAuthorizationAppleIDButtonPress() { | |
let request = ASAuthorizationAppleIDProvider().createRequest() | |
request.requestedScopes = [.fullName, .email] | |
let authorizationController = | |
ASAuthorizationController(authorizationRequests: [request]) | |
authorizationController.delegate = self | |
authorizationController.presentationContextProvider = self | |
authorizationController.performRequests() |
import AuthenticationServices | |
func createButton() { | |
let authorizationButton = ASAuthorizationAppleIDButton() | |
authorizationButton.addTarget(self, action: | |
#selector(handleAuthorizationAppleIDButtonPress), | |
for: .touchUpInside) | |
myView.addSubview(authorizationButton) | |
} |
Just as a reference, here's a UICollectionView with some nice evenly spaced cells.
class ViewController: UIViewController, UICollectionViewDataSource /*, UICollectionViewDelegate */ {
let kReuseIdentifier = "CollectionCellID"
let kNumCellsPerRow:CGFloat = 3.0
let kSpacer:CGFloat = 10.0
var collectionView : UICollectionView!