[英]Implementing Mail within my iOS app
我目前有一个iOS应用,其中从一个项目数组中随机选择一个项目并显示在屏幕上。 我已经在应用程序中内置了“随机性”和显示功能,但现在正尝试对其进行设置,以便您可以从应用程序中通过屏幕上当前显示的阵列中的内容发送电子邮件。 例如,您单击按钮,它将随机显示一个1-10的数字。 我希望用户可以通过电子邮件向屏幕上随机显示的任何数字发送电子邮件,并在电子邮件正文中预先填充屏幕上的数字。 因此,用户得到数字“ 3”,单击电子邮件按钮,电子邮件出现时,“ 3”已预先填充在正文中。
我遇到两个问题,首先是弄清楚如何在当前代码中实现电子邮件功能代码。 我已经构建了一个测试器应用程序,该应用程序具有一个按钮,该按钮可以触发电子邮件撰写的显示,并使用一些静态文本填充正文,因此我对代码的工作原理有基本的了解,但是我不知道如何将其与我已经编写的代码集成。
我的第二个问题是使用屏幕上的随机数预先填充邮件正文。
对于第一个问题,这是我的ViewController.h的外观(我已经添加了MessageUI框架)
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController {
NSArray *testArray;
}
- (IBAction)buttonGo:(UIButton *)sender;
@property (strong, nonatomic) IBOutlet UILabel *testLabel;
@property (strong, nonatomic) NSArray *testArray;
- (void) makePrediction;
@end
我的ViewController.m看起来像
#import "ViewController.h"
#import <MessageUI/MessageUI.h>
@interface ViewController ()
@end
@implementation ViewController
@synthesize testArray;
@synthesize testLabel;
- (void)viewDidLoad
{
[super viewDidLoad];
self.testArray = [[NSArray alloc] initWithObjects:@"number one",@"number `two",@'numberthree", nil];`
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)buttonGo:(id)sender {
NSUInteger index = arc4random_uniform(self.testArray.count);
self.testLabel.text = [self.testArray objectAtIndex:index];
}
- (void) makePrediction {
NSUInteger index = arc4random_uniform(self.
testArray.count);
self.testLabel.text = [self.testArray objectAtIndex:index];
}
- (BOOL) canBecomeFirstResponder {
return YES;
}
- (void) motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
self.testLabel.text = @"";
}
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if ( motion == UIEventSubtypeMotionShake ){
[self makePrediction];
}
}
- (void) motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event {
NSLog(@"motion cancelled");
}
@end
该应用程序运行良好,但是我不确定在哪里实现我的电子邮件代码。 我也不确定如何用数组中的随机选择填充电子邮件正文。 我假设它将与MessageUI的这一点有关
NSString * sentFrom = @"text in email body";
[myMail setMessageBody:sentFrom isHTML:YES];
这是您完成工作的地方,因为您将持有文字
- (IBAction)buttonGo:(id)sender
对于第二个问题,注意isHTML必须设置为NO,以防您的文本不使用它。
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
[mailController setSubject:@"randomNumber"];
[mailController setMessageBody:self.ideaLabel.text isHTML:NO];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.