将数据写入PLIST时,电子邮件将是什么类型?

发布于 2024-12-04 11:08:57 字数 114 浏览 0 评论 0原文

我正在使用 plist 来填充 uitableview。我想知道,因为我的密钥之一是电子邮件,它会是什么类型?数据、字符串等。基本思想是有一个表格,点击电子邮件单元格,就会出现电子邮件模式视图。我该怎么做呢? 谢谢

I'm in the process of using a plist to populate a uitableview. I was wondering, because one of my keys is email, what type would it be? Data, string, etc. The basic idea is to have a table, you tap the email cell, and up comes with the email modal view. How do i go about doing this?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦幻之岛 2024-12-11 11:08:57

我将使用的数据类型是字符串。然后,您可以拉出该绳子并在需要的地方使用它。对于电子邮件,您需要执行以下操作(我假设您能够从 plist 中读取字符串并在 UITableViewCell 中使用它):

#pragma mark -
#pragma mark Compose Mail

-(void)callMailComposer
{
    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
        {
            [self launchMailAppOnDevice];
        }
    }
    else
    {
        [self launchMailAppOnDevice];
    }
}

// Displays an email composition interface inside the application. Populates all the Mail fields. 
-(void)displayComposerSheet
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"My email subject"];

   //Just an extra example if you were wanting to add an attachment :)
   /* NSString* pdfFileName = @"pdf_file.pdf";
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:pdfFileName];

    [picker addAttachmentData:[NSData dataWithContentsOfFile:documentDirectoryFilename] mimeType:@"application/pdf" fileName:pdfFileName]; */

    // Set up recipients
    [picker setCcRecipients:nil];   
    [picker setBccRecipients:nil];
    [picker setToRecipients:[NSArray arrayWithObjects:@"myEmailAddressFromPlist",nil]];

    NSString *emailBody = @"Hey you got mail";
    [picker setMessageBody:emailBody isHTML:YES];

    [self presentModalViewController:picker animated:YES];

    [picker release];
     picker=nil;
}

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{    
    NSString* alertMessage;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            alertMessage = @"Email composition cancelled";
        break;
        case MFMailComposeResultSaved:
            alertMessage = @"Your e-mail has been saved successfully";
        break;
        case MFMailComposeResultSent:
            alertMessage = @"Your email has been sent successfully";
        break;
        case MFMailComposeResultFailed:
            alertMessage = @"Failed to send email";
        break;
        default:
            alertMessage = @"Email Not Sent";
        break;
    }

    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"My application" message:alertMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];

    [self dismissModalViewControllerAnimated:YES];
}

#pragma mark Workaround

// Launches the Mail application on the device.
-(void)launchMailAppOnDevice
{

//You will need to fill these in 
    NSString *recipients = @"mailto:?cc=&subject=";
    NSString *body = @"&body=";
    NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
    email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}

The data type I would use would be a string. You can then pull out this string and use it where you need it. In the case of email, you will need to do the following (I am assuming you are able to read the string out of the plist and use it within a UITableViewCell):

#pragma mark -
#pragma mark Compose Mail

-(void)callMailComposer
{
    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
        {
            [self launchMailAppOnDevice];
        }
    }
    else
    {
        [self launchMailAppOnDevice];
    }
}

// Displays an email composition interface inside the application. Populates all the Mail fields. 
-(void)displayComposerSheet
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;
    [picker setSubject:@"My email subject"];

   //Just an extra example if you were wanting to add an attachment :)
   /* NSString* pdfFileName = @"pdf_file.pdf";
    NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
    NSString* documentDirectory = [documentDirectories objectAtIndex:0];
    NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:pdfFileName];

    [picker addAttachmentData:[NSData dataWithContentsOfFile:documentDirectoryFilename] mimeType:@"application/pdf" fileName:pdfFileName]; */

    // Set up recipients
    [picker setCcRecipients:nil];   
    [picker setBccRecipients:nil];
    [picker setToRecipients:[NSArray arrayWithObjects:@"myEmailAddressFromPlist",nil]];

    NSString *emailBody = @"Hey you got mail";
    [picker setMessageBody:emailBody isHTML:YES];

    [self presentModalViewController:picker animated:YES];

    [picker release];
     picker=nil;
}

// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{    
    NSString* alertMessage;
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            alertMessage = @"Email composition cancelled";
        break;
        case MFMailComposeResultSaved:
            alertMessage = @"Your e-mail has been saved successfully";
        break;
        case MFMailComposeResultSent:
            alertMessage = @"Your email has been sent successfully";
        break;
        case MFMailComposeResultFailed:
            alertMessage = @"Failed to send email";
        break;
        default:
            alertMessage = @"Email Not Sent";
        break;
    }

    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"My application" message:alertMessage delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    [alertView release];

    [self dismissModalViewControllerAnimated:YES];
}

#pragma mark Workaround

// Launches the Mail application on the device.
-(void)launchMailAppOnDevice
{

//You will need to fill these in 
    NSString *recipients = @"mailto:?cc=&subject=";
    NSString *body = @"&body=";
    NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
    email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文