Getting the Recepients list in MFMailComposeViewController
Asked Answered
Y

3

6

I am using MFMailcomposerViewController in my App. Everything is working fine, except that I am in need to Have the no. of recipients and the list of recipients the user is sending to. Any help or solution regarding this issue..

Yankeeism answered 24/1, 2012 at 10:21 Comment(2)
you can get the number of recipients but not there id's..Lim
@Lim Can u give me suggestion regarding how to get the no. of recipients, I also just need that only. Thanks in Advance!!Yankeeism
Y
0

Finally I got the Answer and wanted to share it... I took a great help from [blog]: http://jomnius.blogspot.com/2011/02/how-to-find-mfmailcomposeviewcontroller.html

for (int x=0; x<[emailArray count]-1; x++) {
NSLog(@"%d). %@",x+1,[emailArray objectAtIndex:x]);
NSString *element = [emailArray objectAtIndex:x];
NSArray *arr = [element componentsSeparatedByString:@" & "];
if ([arr count]==1) {
    ++emailCount;
}
else{
    int more = [[[arr objectAtIndex:1] substringToIndex:1] intValue];
    emailCount+=(more+1);
}
}
 - (NSString *)findEmailAddresses:(UIView *)view depth:(NSInteger)count
{
NSString *eAddress = nil;
if (!view)
    return eAddress;
NSMutableString *tabString = [NSMutableString stringWithCapacity:count];
for (int i = 0; i < count; i++)
    [tabString appendString:@"-- "];
NSLog(@"%@%@", tabString, view);
if ([view isKindOfClass:[UITextField class]])
{
    // MAGIC: debugger shows email address(es) in first textField
    // but only if it's about max 35 characters
    if (((UITextField *)view).text)
    {
        eAddress = [NSString stringWithString:((UITextField *)view).text];
        NSLog(@"FOUND UITextField: %@", eAddress ? eAddress : @"");
        [emailArray addObject:eAddress];
    }
}
NSArray *subviews = [view subviews];
if (subviews) {
    for (UIView *view in subviews)
    {
        NSString *s = [self findEmailAddresses:view depth:count+1];
        if (s) eAddress = s;
    }
}
return eAddress;
}
Yankeeism answered 14/6, 2012 at 13:16 Comment(0)
A
2

I dont there is a standard way to do this, the delegate method mailComposeController:didFinishWithResult:error: gives you a reference to the composer view controller after it has been dismissed, but there are no accessors on MFMailComposeViewController which you could use to get the recipient count

A workaround would be to examine the subviews of the view controller, find the text field which was used to hold the recipients and get the text: see here

Ageratum answered 24/1, 2012 at 10:43 Comment(2)
but I am getting that 'aaa.aa @aa.com and 3 more' like string, in that case i cant inspect the email id is correct or not, I am in need fro the same....Yankeeism
like he says in that blog, i think you can only use this to get the number of recipients, if they are beyond that 25 character limit then I dont know of a way to tell what they all wereAgeratum
Y
0

Finally I got the Answer and wanted to share it... I took a great help from [blog]: http://jomnius.blogspot.com/2011/02/how-to-find-mfmailcomposeviewcontroller.html

for (int x=0; x<[emailArray count]-1; x++) {
NSLog(@"%d). %@",x+1,[emailArray objectAtIndex:x]);
NSString *element = [emailArray objectAtIndex:x];
NSArray *arr = [element componentsSeparatedByString:@" & "];
if ([arr count]==1) {
    ++emailCount;
}
else{
    int more = [[[arr objectAtIndex:1] substringToIndex:1] intValue];
    emailCount+=(more+1);
}
}
 - (NSString *)findEmailAddresses:(UIView *)view depth:(NSInteger)count
{
NSString *eAddress = nil;
if (!view)
    return eAddress;
NSMutableString *tabString = [NSMutableString stringWithCapacity:count];
for (int i = 0; i < count; i++)
    [tabString appendString:@"-- "];
NSLog(@"%@%@", tabString, view);
if ([view isKindOfClass:[UITextField class]])
{
    // MAGIC: debugger shows email address(es) in first textField
    // but only if it's about max 35 characters
    if (((UITextField *)view).text)
    {
        eAddress = [NSString stringWithString:((UITextField *)view).text];
        NSLog(@"FOUND UITextField: %@", eAddress ? eAddress : @"");
        [emailArray addObject:eAddress];
    }
}
NSArray *subviews = [view subviews];
if (subviews) {
    for (UIView *view in subviews)
    {
        NSString *s = [self findEmailAddresses:view depth:count+1];
        if (s) eAddress = s;
    }
}
return eAddress;
}
Yankeeism answered 14/6, 2012 at 13:16 Comment(0)
M
0

There is no way to do this as of iOS 6 as mail composition is now done through an XPC service call to a remote process (MailCompositionService). There is a great explanation here: http://oleb.net/blog/2012/10/remote-view-controllers-in-ios-6/. The lowest level in the view hierarchy is now an _UIRemoteView which interfaces to the remote process. The code from the blog post at http://jomnius.blogspot.com/2011/02/how-to-find-mfmailcomposeviewcontroller.html will now alway return nil.

Mendez answered 22/11, 2014 at 10:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.