1

I am trying to sync Events added by my code in calendar application to available mail accounts. I just wanted to confirm that, is it possible in ios5?? I am trying to search for it but not able to find good solution for this. Any one having idea about this??

And I have one more question to ask that is, I am using ios5 new function which create new calendar in iphone's calendar application. Whenever I creates calendar of type local, I am able to create it. But I cant see that calendar in calendar list. Because of some reason it gets hide. Any idea about this??

Thank you in advance

4

1 回答 1

0

首先在您的项目中添加 MessageUI 框架并将这两个导入您的文件中

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

然后制作一个按钮以在 xid 中引用邮件并将其与 IBAction 链接(如下所示):

-(IBAction)emailSettings:(id)sender{

Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
    // check whether the current device is configured for sending emails
    if ([mailClass canSendMail])
    {
        [self displayComposerSheet];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"EMAIL" message:@"No Settings For Email" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
      }
    }

}

-(void)displayComposerSheet 
{
  MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

    picker.mailComposeDelegate = self;
    [picker setSubject:@"StampedeBreakfast!"];

    // Set up recipients
    NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@"third@example.com"]; 

    [picker setToRecipients:toRecipients];
    [picker setCcRecipients:ccRecipients];  
    [picker setBccRecipients:bccRecipients];

    // Fill out the email body text
    NSString *emailBody = [NSString stringWithFormat:@"Hey! This is my Email Body"];
    [picker setMessageBody:emailBody isHTML:NO];


    [self presentModalViewController:picker animated:YES];
 }

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   

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 dismissModalViewControllerAnimated:YES];
}

希望对你有帮助!!

于 2012-05-21T09:57:11.503 回答