checking is user is signed in mail application
i need to know is there any way to check that the user has given an id in mail application so that i can notify the user before calling MFMailComposeViewController that you are not si开发者_如何学编程gned in or you have not given an email id in mail application.
canSendMail
Returns a Boolean indicating whether the current device is able to send email.
+ (BOOL)canSendMail
Return Value
YES if the device is configured for sending email or NO if it is not. Discussion
You should call this method before attempting to display the mail composition interface. If it returns NO, you must not display the mail composition interface.
if([MFMailComposeViewController canSendMail])
{
//do something
}
else
{
// cannot send mail
}
You can check it by below code
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
// We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
UIAlertView *objAlert=[[UIAlertView alloc]initWithTitle:@"No Mail Account" message:@"Please create an account first for sending mail." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[objAlert show];
[objAlert release];
}
}
else
{
UIAlertView *objAlert=[[UIAlertView alloc]initWithTitle:@"No Mail Account" message:@"Please create an account first for sending mail." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[objAlert show];
[objAlert release];
}
精彩评论