iPhone - Anyway to get iPhone's Email App Inside Your Own App? - iphone

Has anyone every embeded the iPhone's Email program inside your own App?
Let me try and simplify that. Tap Tap Revenge allows you to "Challenge A Friend". When you choose to do so they open the standard iPhone email program (if they mimicked it, it looks damn good), within the application with pre-populated data. All you have to do is select a friend from your contacts and press send. You never leave the Tap Tap Revenge App.
Any ideas how this is done?

You need to include the MessageUI.framework into your project, and inside your header file you need to set the delegate:
#import <MessageUI/MessageUI.h>
#interface RootViewController : UIViewController <MFMailComposeViewControllerDelegate> {
MFMailComposeViewController *email;
}
#property (nonatomic, retain) MFMailComposeViewController *email;
Once you do that, you have a few delegate methods inside your implementation file you need to include (You should check to see the result, but I am trying to keep as little code as needed):
#synthesize email;
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[email dismissModalViewControllerAnimated:YES];
}
Wherever you want to use this, you need to initialize and set it up like this:
email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
// Subject
[email setSubject:#"Testing"];
// Optional Attachments
NSData *artwork = UIImagePNGRepresentation([UIImage imageNamed:#"albumart.png"]);
[email addAttachmentData:artwork mimeType:#"image/png" fileName:#"albumart.png"];
// Body
[email setMessageBody:#"This is the body"];
// Present it
[self presentModalViewController:email animated:YES];

Further to Garett's great response, should you get the warning:
'MFMailComposeViewController' may not respond to '-setMessageBody:'
add isHTML: so the complete line reads like:
[mail setMessageBody:#"This is the body" isHTML:NO];

There is two answers for that. For applications that should support iPhone OS prior 3.0 the only way to go is to build a custom message composer. Or you may want to have a look at the component built by Joe Hewitt who wrote the Facebook iPhone app.
http://github.com/joehewitt/three20/blob/master/src/Three20/TTMessageController.h
With iPhone SDK 3.0 you are able to use the Mail message composer UI straight out if the box using the MessageUI.framework as explained above.

messagecomposer is the way to go! mails and sms inside the app, run from iOS 3.1. need sdk 4

Related

Sending sms from phonegap in iphone?

Is it possible to send sms using phonegap in iphone??If yes can anybody suggest me sample code or tutorials to do so???
Is it possible to find out user's phone number using phonegap in iphone??If yes can anybody suggest me sample code or tutorials to do so???
If you want to send sms via phone first you should create a plugin(see phonegap website to see how its done) then in plugin code(it should be native code do it like this :
You must add MessageUI.framework to your Xcode project and include a #import <MessageUI/MessageUI.h> in your header file.
Add these delegates to your header file MFMessageComposeViewControllerDelegate & UINavigationControllerDelegate.
In your IBAction method declare instance of MFMessageComposeViewController say messageInstance to check whether your device can send text use [MFMessageComposeViewController canSendText] in if condition, it'll return Yes/No in the if condition do these:
MFMessageComposeViewController *messageInstance = [[[MFMessageComposeViewController alloc] init] autorelease];
// set body for your messageInstance
messageInstance.body = #"Hello from Shah";
// then decide the recipients for the message as:
messageInstance.recipients = [NSArray arrayWithObjects:#"12345678", #"87654321", nil];
//Set a delegate to your messageInstance as:
messageInstance.messageComposeDelegate = self;
// Then present the messageViewController
[self messageInstance animated:YES];

Attachments using email uri scheme in iOS

I am implementing an iphone application (iOS 4.2) from where I would like to trigger the email client to send messages with attachments. I could effectively use uri schemes in combination with the class NSURL in order to trigger the email app but I was wondering whether it is possible to attach images. I have tried with mailto:whoever#wherever.org?subject=sthg&body=sthgelse&attachment=/path/to/file but the attachments are not included. I know iphone applications are sandboxed therefore it is possible that the email utility were not able to access the path to my image since it is located in my application bundle. On the other hand I was considering to administer my images with the photo manager. (1) Is there a way to include attachments in this way? (2) If so, is it possible to reference images either from my app or from the photo client? I could not find any attachments argument in the mailto RFC but maybe Apple has provided some way to achieve this.
Thanks in advance for your help,
Luis
MFMailComposeViewController will be able to do that, some example of usage belows:
remember to add MessageUI.framework
MFMailComposeViewController *email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
[email setSubject:#"Whatever"];
// Set up recipients
NSArray recipients = [NSArray arrayWithObject:#"whoever#wherever.org"];
[email setToRecipients:recipients];
// Attach an image to the email
UIImage *attachment = ...;
NSData *data = UIImagePNGRepresentation(attachment);
[email addAttachmentData:myData mimeType:#"image/png" fileName:#"ok.png"];
// Fill out the email body text
NSString *emailBody = #"test mail";
[email setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[email release];
Instead of using the mailto: URL scheme, you should use the MFMailComposeViewController which allows you to add attachments. It also has the added benefit that using will not leave your app.
If one does not have account MFMailComposeViewController simply crashes.
Yes, you can call canSendMail first with the result NO(!), what next?
The answer is - use 'mailto:'. It'll popup dialog to create account.

How to develop a SMS client for iOS?

my original title was How to customize TTMessageController for SMS transmission?. I changed this now because I look for any possible solution and not only those with TTMessageController.
Well, I am working on an simple application in xcode4. The user should be able to send SMS from different SMS gateways.
The background logic is quite simple because everything is managed by executing some http requests on an rest api.
The hard thing for me now is to setup the UI and that is where I need help because I am new to iOS development. This is how I want it to be:
http://img222.imageshack.us/img222/3159/bhrfe.png
There should be a recipient picker to either do autosearch on contacts or to directly pick a contact from the contact list. Beside I want only one recipient. And there should be a text area.
I also want to have a label somewhere at the bottom to show the current char number.
Since I did not find those UI elements in xcode4 library I searched for something similar and I found the TTMessageController which gives me the view you see in the picture.
However plus button does not work and I am not sure how to extend all this to do what I want.
I appreciate any idea on this.
For the + Button you can use the address book UI:
// This Code is taken from Apple's sample code QuickContacts
#import <AddressBookUI/AddressBookUI.h>
-(void)showPeoplePickerController {
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
// Display only a person's phone, email, and birthdate
NSArray *displayedItems = [NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonPhoneProperty]];
picker.displayedProperties = displayedItems;
// Show the picker
[self presentModalViewController:picker animated:YES];
[picker release];
}
The <ABPeoplePickerNavigationControllerDelegate> delegate include this methods:
– peoplePickerNavigationController:shouldContinueAfterSelectingPerson:
– peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:
– peoplePickerNavigationControllerDidCancel:
After selecting a person you can save his/her number in an array and in the text field (e.g. comma separated)
.
For the question if it will be approved here is the guideline:
https://developer.apple.com/appstore/resources/approval/guidelines.html
22.6 Apps that enable anonymous or prank phone calls or SMS/MMS messaging will be rejected
You can't use TTMessageController to send sms. The only possible way to send sms is to use MFMessageComposeViewController. Here's a tutorial on how to use it: http://blog.mugunthkumar.com/coding/iphone-tutorial-how-to-send-in-app-sms/

iPhone - MessageUI - framework not found Message

I want to be able to use the iPhones Mail.app inside my application so my users can send a share email without leaving the application. I know 3.0 made this possible.
I have added the framework properly by ctrl clicking on my frameworks folder -> add existing framework.
Added this to the header file of the viewcontroller I want the Mail.app to appear in.
#import <MessageUI/MessageUI.h>
I pop up a UIAlert and on closing I call the function below, There are no errors showing up in my code. Do I have to do something extra inside the Interface Builder? Error Msg is Below
-(void)showEmailModalView {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self; // <- very important step if you want feedbacks on what the user did with your email sheet
NSString * emailSubject = [[NSString alloc] initWithFormat:#"iPhone Subject Test"];
[picker setSubject:emailSubject];
NSString * content = [[NSString alloc] initWithFormat:#"iPhone Email Content"];
// Fill out the email body text
NSString *pageLink = #"http://mugunthkumar.com/mygreatapp"; // replace it with yours
NSString *iTunesLink = #"http://link-to-mygreatapp"; // replate it with yours
NSString *emailBody =
[NSString stringWithFormat:#"%#\n\n<h3>Sent from <a href = '%#'>MyGreatApp</a> on iPhone. <a href = '%#'>Download</a> yours from AppStore now!</h3>", content, pageLink, iTunesLink];
[picker setMessageBody:emailBody isHTML:YES]; // depends. Mostly YES, unless you want to send it as plain text (boring)
picker.navigationBar.barStyle = UIBarStyleBlack; // choose your style, unfortunately, Translucent colors behave quirky.
[self presentModalViewController:picker animated:YES];
[picker release];
[content release];
[emailSubject release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
My ERROR MESSAGE:
ld: framework not found Message
collect2: ld returned 1 exit status
I followed this tutorial:
http://blog.mugunthkumar.com/coding/iphone-tutorial-in-app-email/
After doing some research I found out that the tutorial I was using was perfectly fine! The code had no errors and my problem was the way I added the MessageUI Framework to my project.
Wrong Way.
Ctrl-click on the frameworks folder and select add -> existing frameworks..
Correct Way.
Open up "targets" in the file panel on the left of your xcode screen, double click your project name. A new window will pop open, at the bottom of the new window you can add a new linked library, add one by clicking the little plus sign in the bottom left hand corner. Scroll down to MessageUI and select Add.
If you had already added the MessageUI Framework the wrong way, just simply delete it and proceed with the correct way. If it still doesn't work try shutting down xcode, restarting, and rebuilding your application.
After many hours of searching for an answer this is what worked for me.
The linker command line output will tell you a lot about what XCode is using to try and build your binary, including Framework include paths and the frameworks the linker is including in the build. From there you'll be able to see exactly what XCode is using and what might be missing from your settings. The command line output can be found in one of the output panes in the Build Results window.

i want to send the mail from iphone within my application

I am using the following code to send the mail but when i click on the send button, it come out of the app and send the mail.
i dont want to come out of my application.
-(IBAction) done:(id) sender
{
[self sendEmailTo: #"uttam.beldar#yahoo.com" withSubject: #" Question"
withBody:[textbody text]];
}
- (void) sendEmailTo:(NSString *)to withSubject:(NSString *) subject withBody:(NSString *)body
{
NSString *mailString = [NSString stringWithFormat:#"mailto:?to=%#&subject=%#&body=%#",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];
}
can any one have the solution for this ?
You probably want to look into MFMailComposeViewController - it's the best option for that after the release of iPhone OS 3.0 software.
If you don't want a UI, you need to implement the SMTP protocol, since I don't think there's a built in one. But there is a google code project that provides this, if you want to incorporate it in your app.
You can implement send mail in this easy way.
Tell me if you have problems.
A