ABPeoplePickerNavigationController issue. How to show only contacts with emails? - iphone

Is there any way to provide the screen, where user can see only contacts than contains emails? (because by default I see all contacts on this screen)
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
// place the delegate of the picker to the controll
picker.peoplePickerDelegate = self;
// showing the picker
[self presentModalViewController:picker animated:YES];
// releasing
[picker release];
Then I want to pick up the selected emails.

I do not believe there is a way to get iOS to do this filtering. Note that you need to look for all kinds of email addresses - you have to iterate through the dictionary that you can get. Working with this is a PITA for sure and you have to be careful to not have memory leaks.

Related

Sending email through iPhone application

I'd like to setup a button in the iPhone app I'm making to send an email with the results of some operations performed earlier in the app. I've read other people comment on here that you can use other frameworks but, frankly, I can't find one that actually works. I've heard MailCore is good. Has anyone been able to send an email seamlessly through an iPhone app?
Note: I do not want to exit the app to send the email.
Answer From this Question: How can I send mail from an iPhone application
On iPhone OS 3.0 and later you should use the MFMailComposeViewController class, and the MFMailComposeViewControllerDelegate protocol, that that tucked away in the MessageUI framework. Note you must link the Message UI Framework and import its headers.
#import <MessageUI/MFMailComposeViewController.h>
First to send a message:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:#"My Subject"];
[controller setMessageBody:#"Hello there." isHTML:NO];
if (controller) [self presentModalViewController:controller animated:YES];
[controller release];
Then the user does the work and you get the delegate callback in time:
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;{
if (result == MFMailComposeResultSent) {
NSLog(#"It's away!");
}
[self dismissModalViewControllerAnimated:YES];
}
In this case, your best bet is to use a service like Amazon Simple Email Service (SES). It will enable you to send the email without ever leaving the application (unlike the other solutions listed). Amazon AWS has an iOS SDK which can utilize the SES service. This service is super simple to use, and the cost is extremely low.
http://aws.amazon.com/sdkforios/
MFMailComposeViewController *mailComposer =[[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
NSString *emailBody = #"Write email body text here........";
[mailComposer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];

iOS4 ABNewPersonViewController Loses Data Entered when attempting to add a Photo iPhone 4

I have implemented a basic add contact feature to an iOS 4 application. Following the documentation from Apple, I have created a navigation controller, and set its root view to the ABNewPersonViewController. I have implemented the delegate as well. The basic mechanics all work.
The problem I am having is when you add a photo to the new person that is very large (taking a photo or picking one from the library), the ABNewPersonViewController form returns empty when the camera controls are dismissed. No photo is in the add photo box either. If I pick a small image (say a screenshot from the iPhone), everything works. I can see from the debug output: Received memory warning. Level=1
Has anyone else run into this? Is there a way to set the photo quality to a lower setting for the ABNewPersonViewController? Any help appreciated.
ABNewPersonViewController *abNewPersonView = [[ABNewPersonViewController alloc] init];
abNewPersonView.newPersonViewDelegate = self;
UINavigationController *newNavigationController = [UINavigationController alloc];
[newNavigationController initWithRootViewController:abNewPersonView];
[self presentModalViewController:newNavigationController animated:YES];
[abNewPersonView release];
[newNavigationController release];
If ABNewPersonViewController does not handle memory warnings correctly, file a bug with apple.

Class to manage e-mail from iPhone

I'm working on an iPhone app that offers the user the opportunity to send an e-mail in 3 different places in the app, and for 3 different purposes.
Rather than put the same code for showing the e-mail composer in 3 different view controllers, shouldn't I develop a separate E-mail class, create an instance, and then set properties such as To, CC, BCC, Body, HTML_Or_Not, and so on?
Also, if I create an instance of such a class, and it brings up the e-mail composer, is it OK to release the class even before the e-mail composer has left the screen?
My advice, It's so easy to use the built in mail picker class, just stick with it, you can create a function to setup and show the picker, and use that when you need to like so:
- (void)showMailPicker {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
picker.navigationBar.barStyle = UIBarStyleBlack;
[picker setToRecipients: ...];
[picker setSubject:#"Title"];
// Fill out the email body text
NSString *emailBody = #"email Body...";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
Yes, it's safe to release the picker once you have presented it, and remember that once you present the picker, you can't change the email addresses, subject, body etc...
My aproach would me to encapsulate the whole process of creating, initialising, displaying, dismissing and handling all of the aspects of the mail composer in a class, like a "mail manager" or something.
Then you can create and instance and set the properties you need, and then call "show mail composer" or something to that effect.
I wouldn't recommend releasing this manager class if it will be dealing with the dismissal and handling of the result of the mail composer (ie, handling an error when sending) until after it has finished what it's doing. If you release it too early, you may not have any logical way to dismiss the mail composer or gracefully handle it's results etc.

Click Tabbar to Open Email view in iphone

HI,
I am new to iphone development.I have created the tabbar programmatically and sets five views in the tabbar. Now i want to load an email application view when i clicked the tabbar.This works properly.When i clicked the next tabbar and come back to the email view, i am able to see the normal view and not the Email view.Only one time i am able to see my mail application.I have mail application in the viewDidLoad method. So please guide me.
Here is my code,
- (void)viewDidLoad {
[super viewDidLoad];
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
if ([MFMailComposeViewController canSendMail]) {
[mail setToRecipients:[NSArray arrayWithObjects:#"aaa#gmail.com",nil]];
[mail setSubject:#"Title"];
[self presentModalViewController:mail animated:NO];
}
[mail release];
}
Thanks.
viewDidLoad only runs after the nib file has been loaded, which is once the first time the viewController is shown and then once after any memory warnings are sent.
You want to use viewDidAppear: instead which is called every time after the viewController comes into view.
If you use viewDidAppear method it will be keep on calling the mail view.So use viewWillAppear method.

Reusing a MFMailComposeViewController

I have an app that is built on the TabBar-based app in which I need to have one tab that is basically an email composer. So I'm trying to use a MFMailComposeViewController as one of the tabs. This seems to work fine until I actually go to send an email with the controller. If I do this the MFMailComposeViewController's view disappears and can't be used again.
If I'm reading the docs correctly, the MFMailComposeViewController is normally used modally, but it is supposed to work non-modally as well.
This is how I am adding it to the tab bar...
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.title = #"Feedback";
mailController.tabBarItem.image = [UIImage imageNamed:#"pencil.png"];
[array addObject:mailController];
tabBarController.viewControllers = array;
You you using
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
and hides it with
[self dismissModalViewControllerAnimated:YES];
If so then just comment dismissing.