Following the guide here I am attempting to add Apple sign-in to my iOS app. I have successfully implemented google sign-in with this method but Apple does not seem to be working. I can get to the point where it asks for my apple password but then it just keeps loading without result and I get the following errors:
2020-12-10 13:19:38.020129-0500 Pikit[5268:114225] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
2020-12-10 13:19:38.121991-0500 Pikit[5268:114225] Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service
To be clear these errors appear after I have selected to share my email with the app and before actually entering a password. If I type an incorrect password then it informs me, but if I type the correct password it does not proceed. It does not hang, it simply will not continue with no explanation.
Here is the code that triggers the login flow:
@IBAction func loginPressed(_ sender: UIButton) {
let authUI = FUIAuth.defaultAuthUI()
guard authUI != nil else {
return
}
authUI?.providers = [
FUIEmailAuth(),
FUIGoogleAuth(),
FUIOAuth.appleAuthProvider()
]
authUI?.delegate = self
let authViewController = authUI!.authViewController()
authViewController.modalPresentationStyle = .overCurrentContext
self.present(authViewController, animated: true, completion: nil)
}
//This function is not being triggered
func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) {
if let user = authDataResult?.user{
print("Nice! You've signed in as \(user.uid)")
performSegue(withIdentifier: K.welcomeSegue, sender: self)
}
print(error!)
}
I have also made sure my Firebase project has enabled Apple, that apple sign-in is in my entitlements, and that I have uploaded my iOS auth key. I am running this on a simulator, does it need to be run from a real device?
Update
The authUI
function is not running at all as I have tried inserting a print statement outside of the conditional and received no output. Why would this not be running?
The error appears to be occurring after I call the present()
method.
Update 2
Full console output:
2020-12-11 13:53:55.697034-0500 Pikit[4563:85919] Task <9849E252-C9AF-4F35-88A7-1946BD0B4270>.<2> finished with error [-1003] Error Domain=NSURLErrorDomain Code=-1003 "A server with the specified hostname could not be found." UserInfo={_kCFStreamErrorCodeKey=8, NSUnderlyingError=0x6000006edec0 {Error Domain=kCFErrorDomainCFNetwork Code=-1003 "(null)" UserInfo={_kCFStreamErrorCodeKey=8, _kCFStreamErrorDomainKey=12}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <9849E252-C9AF-4F35-88A7-1946BD0B4270>.<2>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <9849E252-C9AF-4F35-88A7-1946BD0B4270>.<2>"
), NSLocalizedDescription=A server with the specified hostname could not be found., NSErrorFailingURLStringKey=https://firebasedynamiclinks-ipv6.googleapis.com/v1/installAttribution?key=AIzaSyDAKtfpyKw0QG5Db9jtdHYQfAOgI-FASWE, NSErrorFailingURLKey=https://firebasedynamiclinks-ipv6.googleapis.com/v1/installAttribution?key=AIzaSyDAKtfpyKw0QG5Db9jtdHYQfAOgI-FASWE, _kCFStreamErrorDomainKey=12}
2020-12-11 13:53:55.733365-0500 Pikit[4563:85634] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}>
2020-12-11 13:53:55.733582-0500 Pikit[4563:85634] [ProcessSuspension] 0x1098fed80 - ProcessAssertion: Failed to acquire RBS Background assertion 'WebProcess Background Assertion' for process with PID 4565, error: Error Domain=RBSAssertionErrorDomain Code=3 "Target is not running or required target entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"Background" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Target is not running or required target entitlement is missing}
2020-12-11 13:53:55.977723-0500 Pikit[4563:85800] 6.25.0 - [Firebase/Messaging][I-FCM012002] Error in application:didFailToRegisterForRemoteNotificationsWithError: remote notifications are not supported in the simulator
2020-12-11 13:53:56.045387-0500 Pikit[4563:85800] 6.25.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2020-12-11 13:53:56.227368-0500 Pikit[4563:85800] 6.25.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement
2020-12-11 13:53:56.282593-0500 Pikit[4563:85800] 6.25.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
2020-12-11 13:53:56.355765-0500 Pikit[4563:85824] 6.25.0 - [Firebase/Analytics][I-ACS023001] Deep Link does not contain valid required params. URL params: {
dismiss = 1;
"is_weak_match" = 1;
}
2020-12-11 13:54:25.474653-0500 Pikit[4563:85634] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service
2020-12-11 13:54:25.749707-0500 Pikit[4563:85634] Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service
I have tried multiple different methods and read through the documentation many times but still cannot see what I am doing wrong.
Update 3
I have tried replacing each of the certificates/ keys and regenerating new ones with no effect
This is where I have been getting stopped in the sign-in flow:
Update 4
It appears that the error noted above does not occur after signing in, but is unrelated. When logging in I do not get any error. I do not understand why the authUI()
function is not being triggered.
House I have used the Apple Signin in an app but it is in Objective-c. The flow is very simple to test even in Objective-C if you are not used.
In the view with the login I added this sentence for delegate.
@import Firebase;
@import GoogleSignIn;
@interface loginViewController () <GIDSignInDelegate, ASAuthorizationControllerDelegate>
Then after a button tap I execute the AppleSignIn ASAuthorizationControllerDelegate flow like this:
- (IBAction)startSignInWithAppleFlow:(id)sender
{
if (@available(iOS 13.0, *)) {
NSString *nonce = [self randomNonce:32];
self.currentNonce = nonce;
ASAuthorizationAppleIDProvider *appleIDProvider = [[ASAuthorizationAppleIDProvider alloc] init];
ASAuthorizationAppleIDRequest *request = [appleIDProvider createRequest];
request.requestedScopes = @[ASAuthorizationScopeFullName, ASAuthorizationScopeEmail];
request.nonce = [self stringBySha256HashingString:nonce];
ASAuthorizationController *authorizationController = [[ASAuthorizationController alloc] initWithAuthorizationRequests:@[request]];
authorizationController.delegate = self;
authorizationController.presentationContextProvider = self;
[authorizationController performRequests];
}
}
- (NSString *)stringBySha256HashingString:(NSString *)input
{
const char *string = [input UTF8String];
unsigned char result[CC_SHA256_DIGEST_LENGTH];
CC_SHA256(string, (CC_LONG)strlen(string), result);
NSMutableString *hashed = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];
for (NSInteger i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) {
[hashed appendFormat:@"%02x", result[i]];
}
return hashed;
}
- (NSString *)randomNonce:(NSInteger)length
{
NSAssert(length > 0, @"Expected nonce to have positive length");
NSString *characterSet = @"0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._";
NSMutableString *result = [NSMutableString string];
NSInteger remainingLength = length;
while (remainingLength > 0) {
NSMutableArray *randoms = [NSMutableArray arrayWithCapacity:16];
for (NSInteger i = 0; i < 16; i++) {
uint8_t random = 0;
int errorCode = SecRandomCopyBytes(kSecRandomDefault, 1, &random);
NSAssert(errorCode == errSecSuccess, @"Unable to generate nonce: OSStatus %i", errorCode);
[randoms addObject:@(random)];
}
for (NSNumber *random in randoms) {
if (remainingLength == 0) {
break;
}
if (random.unsignedIntValue < characterSet.length) {
unichar character = [characterSet characterAtIndex:random.unsignedIntValue];
[result appendFormat:@"%C", character];
remainingLength--;
}
}
}
return result;
}
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithAuthorization:(ASAuthorization *)authorization API_AVAILABLE(ios(13.0))
{
if ([authorization.credential isKindOfClass:[ASAuthorizationAppleIDCredential class]]) {
ASAuthorizationAppleIDCredential *appleIDCredential = authorization.credential;
NSString *rawNonce = self.currentNonce;
NSAssert(rawNonce != nil, @"Invalid state: A login callback was received, but no login request was sent.");
if (appleIDCredential.identityToken == nil) {
NSLog(@"Unable to fetch identity token.");
return;
}
NSString *idToken = [[NSString alloc] initWithData:appleIDCredential.identityToken encoding:NSUTF8StringEncoding];
if (idToken == nil) {
NSLog(@"Unable to serialize id token from data: %@", appleIDCredential.identityToken);
}
// Initialize a Firebase credential.
FIROAuthCredential *credential = [FIROAuthProvider credentialWithProviderID:@"apple.com"
IDToken:idToken
rawNonce:rawNonce];
// Sign in with Firebase.
[[FIRAuth auth] signInWithCredential:credential completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) {
if (error != nil) {
// Error. If error.code == FIRAuthErrorCodeMissingOrInvalidNonce,
// make sure you're sending the SHA256-hashed nonce as a hex string
// with your request to Apple.
NSLog(@"%ld - %@ - %@", error.code, error.description, error.localizedDescription);
return;
}
// Sign-in succeeded!
// User successfully signed in. Get user data from the FIRUser object
if (authResult == nil) { return; }
FIRUser *user = authResult.user;
// ...
NSLog(@"%@", user);
// ...
[[NSNotificationCenter defaultCenter] postNotificationName:@"LOGIN_SUCCESSFUL" object:nil];
[self dismissViewControllerAnimated:YES completion:nil];
}];
}
}
- (void)authorizationController:(ASAuthorizationController *)controller didCompleteWithError:(NSError *)error API_AVAILABLE(ios(13.0))
{
NSLog(@"Sign in with Apple errored: %@", error);
}
I don't know if you have follow the notes in this link: Apple Sign In with FireBase But if you follow them it should work in physical device, in simulator is not trivial make it work.