【问题标题】:When writing data into a plist what type would an email be?将数据写入 plist 时,电子邮件是什么类型的?
【发布时间】:2011-09-10 20:30:15
【问题描述】:

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

【问题讨论】:

    标签: iphone xcode email uitableview plist


    【解决方案1】:

    我将使用的数据类型是字符串。然后,您可以拉出这条绳子并在需要的地方使用它。对于电子邮件,您需要执行以下操作(我假设您能够从 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]];
    }
    

    【讨论】:

    • 改变这两行 "if(picker) [picker release]; if(picker) picker=nil;"到“[选择器发布];”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-04
    • 1970-01-01
    • 1970-01-01
    • 2020-06-08
    • 1970-01-01
    • 2017-04-03
    • 1970-01-01
    相关资源
    最近更新 更多