Question

I'm creating a registration for my iPhone application and would like to add the ability to guess the phone's default name and email to minimize the amount of typing for the user. What APIs could be used to autofill this information (UITextField, not safari)?

Was it helpful?

Solution 2

I think I might have found a questionable way of using Apple's defaults and UIDevice API that allows for likely discovering of a user's Full Name.

Since many users probably don't change the default device name, we can check to see if it matches the default format and strip out the Full name of the person.

NSString * tryToGuessFullName() {
    NSMutableArray * deviceNamePieces = [NSMutableArray arrayWithArray:[[UIDevice currentDevice].name componentsSeparatedByString:@"’"]];
    if( [deviceNamePieces count] >= 2 ) {
        NSString * possibleSuffix = [deviceNamePieces lastObject];
        if( [possibleSuffix isEqualToString:@"s iPhone"] || [possibleSuffix isEqualToString:@"s iPad"] || [possibleSuffix isEqualToString:@"s iPod"] ) {
            [deviceNamePieces removeLastObject];
            return [deviceNamePieces componentsJoinedByString:@"’"];
        }
    }
    return nil;
}

OTHER TIPS

I don't think the API gives you access to this information. That would be a huge privacy hole.

You could ask the user to select a contact from the address book (presumably them) to help along this process. In doing so, you may get address info too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top