When use my following script, then the picture and the logfile would be a attached file. Also some other Text (the default signature) from the email would be attached as index.htm to the email when i open it with Outlook.
The Email is sent out from the iPad with iOS 7.0.6
In the Mail-Application on the Mac, the Files are in the middle of the text, before the signature of the mail-application would be written.
When i attach only the image, then all would be fine. When i attache also the logfile.txt, then its like I have descripted and in the Mail-Application of the mac, all special keys (german like ä, ü) are not decoded as utf8.
Where did I make the mistake?
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
currentIOS = [[UIDevice currentDevice] systemVersion];
vNumber = #"V"VersionNumber;
subject = [NSString stringWithFormat:#"%# - Meine aktuelle iPad-Nummer",vNumber];
message = [NSString stringWithFormat:#"<p>Hallo liebes EDV-Team,</p> <p>mein Betriebssystem ist: %#</p><p>Und meine iPad-Nummer lautet: %#</p>", currentIOS, udid];
[controller setToRecipients: [NSArray arrayWithObjects:#"email#webpage.de", nil]];
[controller setSubject:subject];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *txtFilePath = [documentsDirectory stringByAppendingPathComponent:#"logfile.txt"];
NSData *noteData = [NSData dataWithContentsOfFile:txtFilePath];
[controller addAttachmentData:noteData mimeType:#"text/plain" fileName:#"logfile.txt"];
UIImage *roboPic = [UIImage imageNamed:#"world_smilie.png"];
NSData *imageData = UIImagePNGRepresentation(roboPic);
[controller addAttachmentData:imageData mimeType:#"image/png" fileName:#"smile.png"];
[controller setMessageBody:message isHTML:YES];
if ([self respondsToSelector:#selector(presentViewController:animated:completion:)]){
[self presentViewController:controller animated:YES completion:nil];
}
I changed the code for the textfile:
I change the code like elio.d told me:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *txtFilePath = [documentsDirectory stringByAppendingPathComponent:#"logfile.txt"];
NSString *txtFileContent = [NSString stringWithContentsOfFile:txtFilePath encoding:NSUTF8StringEncoding error:nil];
NSData *txtFileData = [txtFileContent dataUsingEncoding:NSUTF8StringEncoding];
[controller addAttachmentData:txtFileData
mimeType:#"text/plain"
fileName:#"logfile.txt"];
The logfile.txt would be attached but the signature from the ipad would be attached to the email in ATT00002.htm and now i got also a empty ATT00001.htm
I have the same problem when i change the type of the email (isHTML:NO)
Related
When I try to send link or picture with description paremeter to WeChatMoments or WeChatSession, description is never shown. Every other parameter is shown correctly, except description. There are no errors either. Here goes my code, notice that description is filled:
WXMediaMessage *message = [WXMediaMessage message];
message.title = #"Perfect Title";
message.description = #"Amazing Graphic";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString* path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithUTF8String:thumbnailPath]];
[message setThumbImage:[UIImage imageWithContentsOfFile:path]];
WXImageObject *ext = [WXImageObject object];
NSString* filePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithUTF8String:contentPath]];
ext.imageData = [NSData dataWithContentsOfFile:filePath] ;
message.mediaObject = ext;
SendMessageToWXReq* req = [[[SendMessageToWXReq alloc] init]autorelease];
req.bText = NO;
req.message = message;
req.scene = (true)?WXSceneTimeline:WXSceneSession;
[WXApi sendReq:req];
I've tried code samples from WeChatDeveloper documentation, and even despite of filling description paremeter, it does only show link with title/graphic.
My question is, anybody faced same problem and there is any solution for missing description field?
May problem occur because my app is not yet verified?
How to share image with text(link) using UIDocumentInteractionController in iPhone sdk.
My Code:
NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
// If you go to the folder below, you will find those pictures
NSLog(#"%#",docDir);
NSLog(#"saving png");
NSString *pngFilePath = [NSString stringWithFormat:#"%#/test.png",docDir];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation([self screenShotWithScroll])];
[data1 writeToFile:pngFilePath atomically:YES];
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:pngFilePath]];
_documentInteractionController.delegate = self;
_documentInteractionController.UTI = #"Your Msg";
[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
Image share is working but text share is not working
Can any one help me.
It doesn't look like you can set message text and send an image with UIDocumentInteractionController: that's for opening/viewing/previewing single documents in other apps.
BTW. The UTI property is for declaring the type of the document (see Uniform Type Identifier Concepts).
But you can set a name for the document which mail will use as the subject:
_documentInteractionController.name = #"Your Subject";
To create a mail use the UIActivityViewController with an NSString message and UIImage image activity items.
Hopefully the title made sense. Here's my situation.
I have one PDF created in Pages then exported as a PDF. I then create another PDF within the app. I create the PDF file with this code:
- (void)makePDF:(NSString*)fileName :(NSDictionary*)dictResults
{
pageSize = CGSizeMake(612, 792);
_strPDFJustCreated = fileName;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
[self generatePdfWithFilePath:pdfFileName:dictResults];
}
- (void)generatePdfWithFilePath:(NSString *)thefilePath :(NSDictionary*)dictResults
{
UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);
BOOL done = NO;
do {
...whole lot of coding goodness
done = YES;
} while (!done);
// Close the PDF context and write the contents out.
UIGraphicsEndPDFContext();
}
Both files are attached to the email message with this code:
/**********Attach PDF Files**************/
//get path to pdf file
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* pdfFilePath = [documentsDirectory stringByAppendingPathComponent:strPDFFileName];
//convert pdf file to NSData
NSData* pdfData = [NSData dataWithContentsOfFile:pdfFilePath];
//attach the pdf file
[mailViewController addAttachmentData:pdfData mimeType:#"application/pdf" fileName:strPDFFileName];
//get path to pdf file
NSString* pdf2FilePath = [documentsDirectory stringByAppendingPathComponent:#"OER_MarketingContent.pdf"];
//convert pdf file to NSData
NSData* pdf2Data = [NSData dataWithContentsOfFile:pdf2FilePath];
//attach the pdf file
[mailViewController addAttachmentData:pdf2Data mimeType:#"application/pdf" fileName:#"OER_MarketingContent.pdf"];
[self presentViewController:mailViewController animated:YES completion:NULL];
When I take a peak inside the app folder within the iPhone Simulator folder the pdf files are there, they are recognized by the OS as PDF files and I can open and read them. However, when I get an email message delivered (and don't laugh but we use Lotus Notes), I cannot preview the files I can't an error message saying there is no filter available, when I opt to open it (in Preview) it just hangs.
I use the same code in other apps with no problems. My guess then is that I am doing something different somewhere in my code. I can't see anything obvious so my question would be is there a way to test say NSData for success/failure prior to attaching the file or testing it post attachment but pre email?
Thanks
Don't use UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);. Instead, use: NSData * pdfData = [NSData dataWithContentsOfFile:pdfFileName];.
So, the whole thing should end up looking like:
NSString *fileName = #"Demo.pdf";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
[self generatePdfWithFilePath:pdfFileName];
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:[NSArray arrayWithObject:#"email#email.com"]];
[controller setSubject:#"PDFTEST"];
[controller setMessageBody:#"Your text here" isHTML:NO];
NSData * pdfData = [NSData dataWithContentsOfFile:pdfFileName];
NSString *testFileName = [NSString stringWithFormat:#"PDFNAME"];
[controller addAttachmentData:pdfData mimeType:#"application/pdf" fileName:testFileName];
[self presentModalViewController:controller animated:YES];
This worked for me. Let me know if you have any more questions or if this is unclear. Thanks!
I write the code to open the pdf file located
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *pdfFilePath =[documentsDir stringByAppendingPathComponent:#"421_core_animation_essentials.pdf"];
fileURL = [NSURL URLWithString:pdfFilePath];
QLPreviewController *previewController = [[QLPreviewController alloc] init];
previewController.dataSource = self;
[[self navigationController] pushViewController:previewController animated:YES];
[previewController.navigationItem setRightBarButtonItem:nil];
[previewController release];
It is working while testing in simulator but when testing in iPad device it doesn't work.
please help me.
iOS device file systems are case-sensitive unlike the simulator which isn't.
Therefore check the filename for case sensitivity on:
NSString *pdfFilePath =[documentsDir stringByAppendingPathComponent:#"421_core_animation_essentials.pdf"];
I am using Apple's sample code for the MessageUI and MFMailComposeViewControllerDelegate, and mostly it works great. But for some reason when I implement it, the text in the recipient fields appears out of alignment with the field labels, and you can only see half of the cursor and half of the text while typing. Once you've typed the addresses and exited the field, the text is completely visible, though still out of alignment with the labels. I have looked at other apps' implementations of the MessageUI, and they do not seem to have this problem. has anyone seen this problem and found a solution?
Below is code:
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Data"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:#"email#example.com"];
[picker setToRecipients:toRecipients];
// Attach an attachment to the email
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *csvFile = [documentsDirectory stringByAppendingPathComponent:#"myFile.csv"];
NSData *myData = [NSData dataWithContentsOfFile:csvFile];
NSString *filename = #"myFile.csv";
[picker addAttachmentData:myData mimeType:#"text/csv" fileName:filename];
// Fill out the email body text
NSString *emailBody = #"Attached is the data";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
}
The problem occurs in both the simulator and on device.
Probably, you've got a custom UITextField in your app and have some custom code in - (CGRect)textRectForBounds:(CGRect)bounds. If you'd like to have some category for UITextField class, try to put your specific code directly to the class where you using that instead of using category, which affects all textfields in your app, even in MFMailComposeViewController