簡體   English   中英

在我的iOS應用中實現Mail

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM