iphoneabpersonviewcontroller

Sending invitation from contact list in iPhone


In an app I have to send invite through contact details in iPhone. I know that contact details can be fetch by ABPeoplePickerNavigationController.And on a button action, I am able to get contact details. Now, on selecting any contact name I should be able to send a mail to that contact user.

Now, please share some information.


Solution

  • Check if the contact has email if it does then,

    NSString *subject = [NSString stringWithFormat:@"Subject"];
    NSString *mail = [NSString stringWithFormat:@"contact@mail.com"];
    
    NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"mailto:?to=%@&subject=%@", 
                                               [mail stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding], 
                                               [subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];
    
    [[UIApplication sharedApplication] openURL:url];
    

    FYI : If the user hasn't set the email for particular contact then you won't be able to send email anyway :)