- (IBAction)emailBtnPress {
if ([appDel connectedToInternet]==YES) {
if ([MFMailComposeViewController canSendMail] ){
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSMutableArray *emailIdArray= [[NSMutableArray alloc] init];
for (int i = 0; i < nPeople; i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
ABMultiValueRef multiValue = ABRecordCopyValue(ref, kABPersonEmailProperty);
NSLog(@"%@",multiValue);
int count = ABMultiValueGetCount(multiValue);
NSLog(@"%d",count);
int j;
for(j = 0; j < count; j++) {
NSString *label = (NSString *)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multiValue, j));
NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, j);
NSLog(@"Email for %@: %@", label, value);
[emailIdArray addObject:value];
}
}
NSLog(@"%@",emailIdArray);
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[mailController setCcRecipients:emailIdArray];
[mailController setSubject:@"Sending bulk Email"];
[self presentModalViewController:mailController animated:YES];
[mailController release];
}
else{
[appDel showAlert:@"!Opps" message:@"Your Device should not configured the mail account."];
}
}
else{
[appDel showAlert:@"!Opps" message:@"Check your network connection."];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Result: canceled");
break;
case MFMailComposeResultSaved:
NSLog(@"Result: saved");
break;
case MFMailComposeResultSent:
NSLog(@"Result: sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Result: failed");
break;
default:
NSLog(@"Result: not sent");
break;
}
[self becomeFirstResponder];
[controller dismissModalViewControllerAnimated:YES];
}
if ([appDel connectedToInternet]==YES) {
if ([MFMailComposeViewController canSendMail] ){
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
NSMutableArray *emailIdArray= [[NSMutableArray alloc] init];
for (int i = 0; i < nPeople; i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople, i);
ABMultiValueRef multiValue = ABRecordCopyValue(ref, kABPersonEmailProperty);
NSLog(@"%@",multiValue);
int count = ABMultiValueGetCount(multiValue);
NSLog(@"%d",count);
int j;
for(j = 0; j < count; j++) {
NSString *label = (NSString *)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multiValue, j));
NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, j);
NSLog(@"Email for %@: %@", label, value);
[emailIdArray addObject:value];
}
}
NSLog(@"%@",emailIdArray);
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate = self;
[mailController setCcRecipients:emailIdArray];
[mailController setSubject:@"Sending bulk Email"];
[self presentModalViewController:mailController animated:YES];
[mailController release];
}
else{
[appDel showAlert:@"!Opps" message:@"Your Device should not configured the mail account."];
}
}
else{
[appDel showAlert:@"!Opps" message:@"Check your network connection."];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Result: canceled");
break;
case MFMailComposeResultSaved:
NSLog(@"Result: saved");
break;
case MFMailComposeResultSent:
NSLog(@"Result: sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Result: failed");
break;
default:
NSLog(@"Result: not sent");
break;
}
[self becomeFirstResponder];
[controller dismissModalViewControllerAnimated:YES];
}
No comments:
Post a Comment