将事件同步到iPhone中的可用邮件帐户

时间:2012-05-21 09:08:51

标签: iphone ipad ios5

我正在尝试将日历应用程序中的代码添加的事件同步到可用的邮件帐户。我只是想确认一下,ios5有可能吗?我正在尝试搜索它,但无法为此找到好的解决方案。任何人都有这个想法?

我还有一个问题要问的是,我正在使用ios5新功能在iphone的日历应用程序中创建新日历。每当我创建本地类型的日历时,我都能够创建它。但我无法在日历列表中看到该日历。由于某种原因,它被隐藏起来。对此有任何想法??

提前谢谢

1 个答案:

答案 0 :(得分: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];
}
希望这会对你有帮助!!