Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iphone应用程序中将电子邮件接收设置为NSString_Iphone_Ios_Email - Fatal编程技术网

如何在iphone应用程序中将电子邮件接收设置为NSString

如何在iphone应用程序中将电子邮件接收设置为NSString,iphone,ios,email,Iphone,Ios,Email,我正在从iphone应用程序发送电子邮件,我希望发送到的电子邮件应为var emailTO的值或地址,应自动输入 NSString*emailTO=@"ali@yahoo.com"; [picker setRecipients:[NSArray arrayWithObject:emailTO]]; 但是它不知道如何以这种方式实现,这要感谢您应该使用 [picker setRecipients:[NSArray arrayWithObjects:emailTO,nil]];

我正在从iphone应用程序发送电子邮件,我希望发送到的电子邮件应为var emailTO的值或地址,应自动输入

     NSString*emailTO=@"ali@yahoo.com";


    [picker setRecipients:[NSArray arrayWithObject:emailTO]];
但是它不知道如何以这种方式实现,这要感谢您应该使用

[picker setRecipients:[NSArray arrayWithObjects:emailTO,nil]];
试着用这个

NSArray *array = [NSArray arrayWithObject:@"ali@yahoo.com"];

        if ([MFMailComposeViewController canSendMail])
        {

            MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
            mailViewController.mailComposeDelegate = self;

            [mailViewController setToRecipients:array];

            [self presentViewController:mailViewController animated:YES completion:NULL];
        }

        else
        {

            NSLog(@"Device is unable to send email in its current state.");

        }

试试这个。希望对您有所帮助。请注意,您需要将MessageUI框架添加到应用程序中

#import <MessageUI/MessageUI.h>
使用
MFMailComposeViewControllerDelegate协议:
Delegate函数确认结果

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Result: canceled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Result: saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Result: sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Result: failed");
            break;
        default:
            NSLog(@"Result: not sent");
            break;
    }
}
描述 设置要包含在电子邮件“收件人”字段中的初始收件人

- (void)setToRecipients:(NSArray*)toRecipients
参数 收件人
NSString
对象组成的
数组
,每个对象都包含
单个收件人的
电子邮件地址
,如果要打开
iPhone
电子邮件应用程序,请使用下面的代码。因此,您无需添加
MFMailComposeViewController

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setToRecipients:[NSArray arrayWithObject:[NSString stringWithFormat:@"%@,@"ur Receipent data"]]]];
NSString *subject = @"";

NSString *body = @"";

NSString *address = @"test@gmail.com";

NSString *cc = @"";

NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body];

NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [[UIApplication sharedApplication] openURL:url];
试试这个

    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
                mailViewController.mailComposeDelegate = self;
                [picker setRecipients:[NSArray arrayWithObject:@"your email address"]];
                [self presentViewController:mailViewController  animated:YES completion:nil];

意思是说你在收件人中找不到这个
电子邮件地址
?如果答案正确,请将我的答案标记为正确。这看起来不错,你在观察什么行为?你正在做的是:一个包含单个对象的数组,一个包含字符串的数组。这是怎么回事?我想首先我创建了
NSMutableArray
,并将电子邮件地址列表添加为
String
对象。作为
setToRecipients
required
NSArray
所以我将其转换为?当您执行
[NSArray arrayWithObject:
时,您将创建一个包含另一个数组的数组。您应该执行的操作是:
[picker setRecipients:toRecipients]
。但这与OP的代码没有什么不同。所以它不起作用还有其他原因。这是错误的。你不能将sentinel与
阵列一起使用。WithObject:
@bit whacker现在看起来好多了,我已经取消了我的反对票。但正如我已经说过的,我仍然不知道这将如何解决OP的问题。不过,公平地说,OP没有表现出来我们需要完整的代码。这是错误的。您不能将sentinel与
arrayWithObject:
NSString *subject = @"";

NSString *body = @"";

NSString *address = @"test@gmail.com";

NSString *cc = @"";

NSString *path = [NSString stringWithFormat:@"mailto:%@?cc=%@&subject=%@&body=%@", address, cc, subject, body];

NSURL *url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; [[UIApplication sharedApplication] openURL:url];
    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
                mailViewController.mailComposeDelegate = self;
                [picker setRecipients:[NSArray arrayWithObject:@"your email address"]];
                [self presentViewController:mailViewController  animated:YES completion:nil];