我想创建一个制作/创建文本文件(.txt)的iOS应用程序,然后将其作为电子邮件发送。
我遇到的问题是要加密的数据弹出错误“使用未声明的标识符”
[mailController addAttachmentData:dataToBeEncrypted mimeType:@“text / plain”
这是我的.m文件
//
// FileIoViewController.m
// FileIo
//
// Created by Flare gun on 6/24/14.
// Copyright (c) 2014 Flaregunapplications. All rights reserved.
//
#import "FileIoViewController.h"
@interface FileIoViewController ()
@end
@implementation FileIoViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) writeToTextFile{
//get the documents directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//make a file name to write the data to using the documents directory:
NSString *fileName = [NSString stringWithFormat:@"%@/textfile.txt",
documentsDirectory];
//create content - four lines of text
NSString *content = @"One\nTwo\nThree\nFour\nFive";
//save content to the documents directory
[content writeToFile:fileName
atomically:NO
encoding:NSStringEncodingConversionAllowLossy
error:nil];
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate =self;
[mailController setSubject:@"Records"];
[mailController setMessageBody:@"" isHTML:YES];
[mailController addAttachmentData:dataToBeEncrypted mimeType:@"text/plain" fileName:@"Records.txt"];
[self presentModalViewController:mailController animated:YES];
[mailController release];
} else {
//Pop up a notification
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not send email. Verify Internet conneciton and try again." delegate:nil cancelButtonTitle:@"Done" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
@end
答案 0 :(得分:1)
宣布dataToBeEncrypted
使用类似的内容:
NSData *dataToBeEncrypted = [NSData dataWithContentsOfFile:filename];