iPhone - ABPeoplePickerNavigationController: Show "Phone" properties but not the Ringtone - iphone

Using the code below, I'm bringing up a person picker so the user can choose either a phone or an email address. I've set the displayable properties to Email and Phone, but the "Ringtone" property is visible in the phone group. Given the purpose of this instance of Person picker, the Ringtone choice makes absolutely no sense to display here. Anyone know how to get rid of it in the phone group?
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
NSArray *propertiesToShow = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonEmailProperty],
[NSNumber numberWithInt:kABPersonPhoneProperty], nil];
[picker setDisplayedProperties:propertiesToShow];
[picker setPeoplePickerDelegate:self];
[self presentModalViewController:picker animated:YES];
[picker release];

Related

Simulating sent SMS on iPhone

Since debugging is extremely slow with Xcode 4.3 on iOS 5.1 when starting/installing the app on the device I use the simulator which starts much faster. (see my question regarding this issue here https://stackoverflow.com/questions/11541288/xcode-4-3-with-ios5-1-pauses-about-10secs-when-debug-starts-simulator-starts-i)
So all I need to do is something like this:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = delegate;
NSString *s = #"1234567";
picker.recipients =[NSArray arrayWithObject: s];
picker.body =smsTxt;
if (simulationMode) {
MessageComposeResult result = MessageComposeResultSent; <-----------
[delegate messageComposeViewController:picker didFinishWithResult: result];
} else
[delegate presentModalViewController:picker animated:YES];
Here the problem is now that when executing on iOS-Simulator the MFMessageComposeViewController can't be instantiated and always yields nil.
Is there a way to create another object MyOwnMFMessageComposeViewController on iOS simulator which is compatible to MFMessageComposeViewController and can be passed in the same method like MFMessageComposeViewController?
Something like this:
MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init];
picker.messageComposeDelegate = delegate;
NSString *s = #"1234567";
picker.recipients =[NSArray arrayWithObject: s];
picker.body =smsTxt;
if (simulationMode) {
MyOwnMFMessageComposeViewController *mypicker = [[MFMessageComposeViewController alloc] init];
mypicker.messageComposeDelegate = delegate;
NSString *s = #"1234567";
mypicker.recipients =[NSArray arrayWithObject: s];
mypicker.body =smsTxt;
MessageComposeResult result = MessageComposeResultSent;
picker = (MFMessageComposeViewController) mypicker;
[delegate messageComposeViewController:picker didFinishWithResult: result];
} else
[delegate presentModalViewController:picker animated:YES];
What you are looking for is called a 'mock object' and is often used in test driven development. Basically what you do is create a subclass of MFMessageComposeViewController. This subclass works exactly the same as mfmessagecomposeviewcontroller except you also create instance variables to show that something has happened.
So for example when your delegate calls messageComposeViewController:didFinishWithResult. The mock object would likely store the result and a flag that that method had been fired. Note that this won't actually send anything, but simply tells you that the delegate fired and on a real object will work.

xcode mfmailcomposeviewcontroller lock setToRecipients

I have app that user contact me
The problem is that the users can put any email address, but I want to lock or do something to setToRecipients so that user can't make any change in this field.
Here is my code
MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
[composer setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[composer setToRecipients:[NSArray arrayWithObjects:#"123#abc.com", nil]];
[composer setSubject:#"subject here"];
[composer setMessageBody:#"message here" isHTML:NO];
[composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:composer animated:YES];
[composer release];
}
Any help or guide !!
thanx & regards
You can't as MFMailComposeViewController does not provide that functionality.
By the look of it, you can't. And the reason is that apple has safety protection to ensure you app doesn't auto send spam emails, in their point of view, it's the user should always have flexibility to choose where the email goes to.

MFMailComposer is not working in iPhone 3GS

I have this piece of code for MFMailComposer working fine in the simulator and iPhone 4, but it crashes on 3GS. What is the reason and what is the way to resolve it?
I checked it with breakpoints. mailPicker is not allocated with memory.
MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
// Set the subject of email
[mailPicker setSubject:#"Somebody got place in my sh*t list"];
NSString *emailBody = #"I just added somebody to my s**t list";
// This is not an HTML formatted email
[mailPicker setMessageBody:emailBody isHTML:NO];
// Create NSData object as PNG image data from camera image
NSData *data = UIImagePNGRepresentation([self captureScreen]);
// Attach image data to the email
// 'CameraImage.png' is the file name that will be attached to the email
[mailPicker addAttachmentData:data mimeType:#"image/png" fileName:#"CameraImage"];
// Show email view
[self presentModalViewController:mailPicker animated:YES];
// Release picker
[mailPicker release];
If at least one email account is enabled on the device, the following call should return YES:
[MFMailComposeViewController canSendMail]
Conversely, if all accounts are disabled/removed, it will return NO.

Problem with MFMailComposeViewController - User Can't Edit Mail Body - iPhone

I usually use the below code to allow the user to submit feedback on my apps. However for some reason in my OpenGL app the below code has a problem. It opens the email form correctly, however the form is locked - i.e the user can't actually edit the body of the text. Can anybody spot why this is happening ?
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Feedback on Stop That Bomb Free !"];
NSArray *toRecipients = [NSArray arrayWithObject:#"anemail#gmail.com"];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody =
[NSString stringWithFormat:#"Hi Martin, I would like to make the following comment : "];
[picker setMessageBody:emailBody isHTML:YES];
picker.navigationBar.barStyle = UIBarStyleBlack;
[inputController presentModalViewController:picker animated:YES];
[picker release];
From reading your code I can find some things you should change:
Replace:
NSString *emailBody = [NSString stringWithFormat:#"Hi Martin, I would like to make the following comment : "];
With:
NSString *emailBody = #"Hi Martin, I would like to make the following comment : ";
As you are not using any formatting; you dont need to call the class method to create the simple string.
The other thing you can change is the fact that you message does not contain HTML.
So you dont need isHTML:YES.
I have tested this successfully on a sample app.
I imagine the problem is with the view controller presenting the view, rather than the messageUI view.

iPhone application lags after launching and dismissing MFMailComposeViewController

I have an application that uses a table view controller to display some items, after clicking on one of those items you may select to email this item. Once that happens I use the code provided by apple "MailComposer", and send the mail. However after this the scrolling in the table view is not as smooth as before.
I checked with "Leaks" and there are no leaks in my code, however there is a great deal of object allocation when the modal view controller for the MFMailComposeViewController, and when i dismiss my controller, all that object allocation is still there. How can i get rid of all that object allocation?. Any help will be greatly appreciated. Thank you.
-Oscar
UPDATE:
I have realized the lag only happens once you click on the To: textfield on the MFMailComposeViewController and type something, once something has been typed there will be a memory leak and the application will be sluggish. This exact same thing also happens in Apple's Mail Composer. I am using the simulator maybe this is why?. Does anyone else have a simmilar experience?
The way I am pressenting my controller is:
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString *mailSubject = appDelegate.mailTitle;
NSString *mailBody = appDelegate.mailLink;
NSString *formattedString = [NSString stringWithFormat:#"<a href='%#'>%#</a>", mailBody, mailBody];
[picker setSubject:mailSubject];
// Set up recipients
//NSArray *toRecipients = [NSArray arrayWithObject:#"somemail#hotmail.com"];
//NSArray *ccRecipients = [NSArray arrayWithObjects:#"second#example.com", #"third#example.com", nil];
//NSArray *bccRecipients = [NSArray arrayWithObject:#"fourth#example.com"];
//[picker setToRecipients:toRecipients];
//[picker setCcRecipients:ccRecipients];
//[picker setBccRecipients:bccRecipients];
// Attach an image to the email (Warning this causes a memory leak aknowledged by Apple)
//NSString *path = [[NSBundle mainBundle] pathForResource:#"news_icon" ofType:#"png"];
//NSData *myData = [NSData dataWithContentsOfFile:path];
//[picker addAttachmentData:myData mimeType:#"image/png" fileName:#"rainy"];
// Fill out the email body text
[picker setMessageBody:formattedString isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
and dimissing it here:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
....
[self dismissModalViewControllerAnimated:YES];
}
It's a known memory leak in MFMailComposeViewController class (as of iOS 4.2 SDK). The leaks can be even seen in the MailComposer sample project by Apple. Try to run the app with Allocations instrument and notice the Overall Bytes growing up every time you click cancel and show the composer again.
See below for the similar discussion:
http://discussions.apple.com/thread.jspa?threadID=2158170
https://devforums.apple.com/thread/23510?tstart=15
https://devforums.apple.com/message/121093#121093
Make sure you use
controller.mailComposeDelegate = self;
and not
controller.delegate = self;