문제

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)?

도움이 되었습니까?

해결책 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;
}

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top