Centering Picture In MFMailComposeViewController (iOS) - ios

Is it possible to center an image when attaching it to the MFMailComposeViewController in XCode? Here's the code I'm using:
NSString *path = [[NSBundle mainBundle] pathForResource:#"millersicon" ofType:#"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:#"image/png" fileName:#"millersicon"];
It places the image in the e-mail when the Mail Application comes up but it's left aligned. Is there a way to center it? I couldn't find any information on it. Thanks.

Related

Download XLS sheet from server to IPhone

How to download a .xls sheet from server and save it in iPhone memory, if spreadsheet is bigger in size then process took place in background.
Try this in any method.
NSURL *url=[NSURL URLWithString:#"http://en.wikipedia.org/wiki"]; //Your URL here
NSData *dbFile = [[NSData alloc] initWithContentsOfURL:url];
NSString *resourceDocPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent]stringByAppendingPathComponent:#"Documents"]];
NSString *filePath = [resourceDocPath stringByAppendingPathComponent:#"Text_file.xls"];
[dbFile writeToFile:filePath atomically:YES];
I assume that you server doesn't require authentication

How to remove the path from an attachment when calling addAttachmentData?

When adding an attachment to an email, the file name gets it's complete path.
For a file located in:
/var/mobile/Applications/C3BBAA5F-07FE-4E26-9661-CB492E06BD2E/Documents/
I'm getting as a result, a file named:
_var_mobile_Applications_C3BBAA5F-07FE-4E26-9661-CB492E06BD2E_Documents_Clock.sqlite
When I need my filename to be:
Clock.sqlite
Here's my code:
NSString *path = [self getDatabaseFilePath];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:#"application/x-sqlite3" fileName:path];
How can I get the attachment to have only the filename and extension, without the complete path?
Thank you!
This should do what you want:
NSString *path = [self getDatabaseFilePath];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:#"application/x-sqlite3" fileName:[path lastPathComponent]];

NSURL may not respond warning +encryptedFileWithPath

I am using the following code which is coming up with a warning. The code does display the correct image - but how can I get rid of the warning?
NSString *indexPath = [[NSBundle mainBundle] pathForResource:name ofType:#"png" inDirectory:#"tunes"];
NSURL *url = [NSURL encryptedFileURLWithPath:indexPath];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:data];
warning 'NSURL may not respond to +encryptedFileWithPath:'
That is because NSURL does not have a method called `encryptedFileWithPath:'. If you have copied your code from here, you probably didn't read the article carefully enough:
If you are familiar with NSURL and its class methods then you may have
spotted the unfamiliar encryptedFileURLWithPath: method. I have
extended NSURL using a category to add this method as a convenience.

How to add gif to attachment in iPhone mail?

I add .jpg this way:
UIImage *sentPic = self.image;
NSData *imageData = UIImageJPEGRepresentation(sentPic, 1);
[picker addAttachmentData:imageData mimeType:#"image/jpg" fileName:#"pic.jpg"];
I change it to "image/gif".But it doesn't work fine. Th Gif is just a still image in the mail.
NSData *imageData = [[NSData alloc] initWithContentsOfFile:pathToGifFile];
[picker addAttachmentData:imageData mimeType:#"image/gif" fileName:#"pic.gif"];
[imageData release];
This would add it as attachment, but I'm not sure if that's what you want, or you want to display the image inside the message?
Have you ever tried HTML code in your email like this:
NSString *emailBody = #"It is a gif email!";
emailBody = [EmailBody stringByAppendingString:#"<img src='http://xx.xx.pic.gif'>"];
[picker setMessageBody:emailBody isHTML:YES];
The code I haven't tested, you can have a try. Tell us if it works.
I just tested this. Works great:
NSString *pathForGif = [[NSBundle mainBundle] pathForResource: #"<your file name>" ofType: #"gif"];
NSData *gifData = [NSData dataWithContentsOfFile: pathForGif];
[mailController addAttachmentData:gifData mimeType:#"image/gif" fileName:#"EmailGIF.gif"];
[self presentModalViewController:mailController animated:YES];

how to attatch a file to the mail using default mail composer

i hav a file with some data and i want to attach this file to mail, and i am using the default mail composer ...
any idea how to attach the file to mail before sending to receipents....
Thanks in advance....
Example with an attached image:
NSData *myData = UIImagePNGRepresentation(myImage);
[mailComposer addAttachmentData:myData mimeType:#"image/png" fileName:#"MyImage"];
NSString *path = [[NSBundle mainBundle] pathForResource:#"bg" ofType:#"jpg"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[controller addAttachmentData:myData mimeType:#"image/jpg" fileName:#"Attachment-1"];
[self presentModalViewController:controller animated:YES];

Resources