Email Verification

Depending on your flow, when a user registers with your application they will need to verify their email. The user does this by opening a link in an email to a web page that you host. The web page accepts a code from the email and verifies the user’s email address using Janrain’s javascript widget. The user experience can be improved by launching your application and displaying a friendly greeting upon successful email verification. This guide will walk through the steps to do that.

Setup a custom url scheme for your application

Edit your application’s Info.plist as in https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW50 to add a custom URL scheme.

In your AppDelegate implement something like the following:

        - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
          sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {

            if ([[url scheme] isEqualToString:@"your.custom.url.scheme"]) {
                if ([[url path] isEqualToString:@"/verified"]) {
                    NSString *displayName = [[url query] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

                    // In SimpleCaptureDemo we would add something like this, for example.
                    UINavigationController *navigationController = (UINavigationController *)[self.window rootViewController];
                    [navigationController popToRootViewControllerAnimated:NO];
                    RootViewController *rootViewController = (RootViewController *)[navigationController visibleViewController];
                    [rootViewController emailWasVerified:displayName];
                }
                return YES;
            }

            return NO;
        }

And in RootViewController (for example) add something like this:

RootViewController.h

(void)emailWasVerified:(NSString *)displayName;

RootViewController.m

- (void)emailWasVerified:(NSString *)displayName {
    NSString *title = [NSString stringWithFormat:@"Welcome back %@", displayName];
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
                                                        message:@"Your email has been verified. Please sign in."
                                                       delegate:self
                                              cancelButtonTitle:@"Cancel"
                                              otherButtonTitles:@"Sign In", nil];
    alertView.tag = EMAIL_VERIFIED_ALERT_VIEW;
    [alertView show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (alertView.tag == EMAIL_VERIFIED_ALERT_VIEW && buttonIndex != alertView.cancelButtonIndex) {
        [self signOutCurrentUser];
        [self startSignInForProvider:nil];
    }
}

Resending Email Verification

You may want to provide your users with the ability to resend the email verification in case they lost the original email or the verification code has expired. You can trigger this directly by calling \[JRCapture resendVerificationEmail:delegate:\]. If resending the email is successful then the resendVerificationEmailDidSucceed delegate method will be invoked, otherwise resendVerificationEmailDidFailWithError: will be called. The generated email contains the url in the verify_email_url capture setting with a verification_code parameter appended.