我正在尝试使用MFMailComposeViewController发送电子邮件.我可以发送附有图像的电子邮件,但是当我尝试附加mp3或mp4文件时,我收到以下消息:
DA |无法在/tmp/DAAccountsLoading.lock中打开锁定文件.无论如何我们都会加载帐户,但可能会发生不好的事情
(如果似乎在我开始填写"To"字段后出现,并且发送消息失败.
这是我的代码(HelperUtils类只是我创建的东西,我确定问题不存在):
NSData *myData = [NSData dataWithContentsOfFile:[HelperUtils getPathWithEnding:media.name]];
NSString *mimeTypeStr = [HelperUtils getMimeTypeOfFileWithPath:[HelperUtils getPathWithEnding:media.name]];
NSLog(mimeTypeStr);
NSLog([HelperUtils getPathWithEnding:media.name]);
[picker addAttachmentData:myData mimeType:mimeTypeStr fileName:media.name];
Run Code Online (Sandbox Code Playgroud) 我想以编程方式从我的应用程序发送.doc文件作为电子邮件附件.
我使用以下代码在电子邮件正文中显示超链接.但它只显示邮件正文中的文本.当我点击它时.没有任何反应.
-(IBAction)emailToFriend:(id)sender
{
NSLog(@"E-Mail...");
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"My Subject"];
[controller setMessageBody:@"<a href=\"http://www.google.com\">http://www.google.com</a>" isHTML:YES];
[self presentModalViewController:controller animated:YES];
[controller release];
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我这里有什么问题吗?我检查了问题MFMailComposeViewController:我如何将可点击的URL链接嵌入到电子邮件正文中它没有帮助我
好的,这一直困扰着我一段时间......
我已检查过,所有其他问题/答案都与非ARC项目有关.
每当我提出MFMCvc并且我快速取消消息时,我就会在iPhone上收到Thread1:EXEC_BAD_ACCESS错误消息.可以在iPad上正常工作,或者我让它静坐(比如30秒或更长时间)
有什么建议吗?(除了放一个计时器而不是在计时器启动之前解雇?)
BTW我对MFMessageComposeViewController做了同样的事情,它在iPhone和iPad上运行良好.
这是我的代码来呈现它
if (([action isEqualToString:@"EMail"]) && contact.length>0)
{
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
if([MFMailComposeViewController canSendMail]) {
[mailViewController setSubject:@""];
[mailViewController setMessageBody:@"" isHTML:NO];
[mailViewController setToRecipients:[NSArray arrayWithObject:contact]];
[mailViewController setMailComposeDelegate:self];
[self presentModalViewController:mailViewController animated:NO];
}
}
Run Code Online (Sandbox Code Playgroud)
这是我解雇它的地方
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send EMail" message:@"EMail Has Been Cancelled"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
break;
case MFMailComposeResultFailed:
{
NSLog(@"Error");
}
break;
case MFMailComposeResultSent:
{
UIAlertView *alert = …Run Code Online (Sandbox Code Playgroud) 我使用以下内容来显示mailViewController
-(IBAction)sendMailbuttonTapped {
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
mailCont.mailComposeDelegate = self;
[mailCont setSubject:@"yo!"];
[mailCont setToRecipients:[NSArray arrayWithObject:@"surendherbtech@gmail.com"]];
[mailCont setMessageBody:@"Don't ever want to give you up" isHTML:NO];
[self presentModalViewController:mailCont animated:YES];
[mailCont release];
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}
Run Code Online (Sandbox Code Playgroud)
它显示良好但我现在需要的是,我希望在他点击按钮时不用用户的知识发送邮件.它必须在没有用户点击发送选项的情
任何人都可以告诉我如何自动发送邮件提前谢谢
我在我的App Delegate中有这个代码:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"Nav Bar.png"] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
这很好用,但我使用它MFMailComposeViewController,我希望它具有默认的NavigationBar外观.
我怎么做?
编辑:
我试过这段代码:
[[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], [UIViewController class], nil] setBackgroundImage:[UIImage imageNamed:@"Textured Background.png"] forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
我也试过只有这个代码.没有什么变化.默认导航栏,包括邮件视图控制器.
我认为它可能与之相关appearanceWhenContainedIn:.有谁知道MFMailComposeViewController会包含什么?
我正在努力在我的应用程序中实现Peek和Pop,以及UIPreviewActions.我的PreviewView都设置好了,Peek和Pop都很棒,我的问题是添加UIPreviewActions.当然,您必须将UIPreviewAction方法放在预览控制器中,那么如何获取它然后关闭该视图,并在其父控制器中打开视图?
我在PreviewController中:
- (NSArray*)previewActionItems {
// setup a list of preview actions
UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"Post to Facebook" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
}];
UIPreviewAction *action2 = [UIPreviewAction actionWithTitle:@"Message" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
}];
UIPreviewAction *action3 = [UIPreviewAction actionWithTitle:@"Email" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
[self displayComposerSheet];
}];
// add them to an arrary
NSArray *actions = @[action1, action2, action3];
// and return them …Run Code Online (Sandbox Code Playgroud) 我想使用MFMessageComposeViewController向多个收件人发送一条消息,我无法添加第二个等收件人
这是我的代码:
@IBAction func sendSms(sender: AnyObject) {
if (MFMessageComposeViewController.canSendText())
{
let controller = MFMessageComposeViewController()
controller.body = self.textView.text
controller.recipients = [self.phoneField.text!]
controller.messageComposeDelegate = self
self.presentViewController(controller, animated: true, completion: nil)
}
else
{
print("Error")
}
}
extension MyViewController : MFMessageComposeViewControllerDelegate
{
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult)
{
controller.dismissViewControllerAnimated(true, completion: nil)}
}
}
Run Code Online (Sandbox Code Playgroud)
任何建议如何将其发送给多个收件人?
非常感谢 Paulw11 帮助我解决了这个问题。我在这里添加了完整的代码以便于重用:
班级:
import UIKit
import MessageUI
struct Feedback {
let recipients: [String]
let subject: String
let body: String
let footer: String
}
class FeedbackManager: NSObject, MFMailComposeViewControllerDelegate {
private var feedback: Feedback
private var completion: ((Result<MFMailComposeResult,Error>)->Void)?
override init() {
fatalError("Use FeedbackManager(feedback:)")
}
init?(feedback: Feedback) {
guard MFMailComposeViewController.canSendMail() else {
return nil
}
self.feedback = feedback
}
func send(on viewController: UIViewController, completion:(@escaping(Result<MFMailComposeResult,Error>)->Void)) {
let mailVC = MFMailComposeViewController()
self.completion = completion
mailVC.mailComposeDelegate = self
mailVC.setToRecipients(feedback.recipients)
mailVC.setSubject(feedback.subject)
mailVC.setMessageBody("<p>\(feedback.body)<br><br><br><br><br>\(feedback.footer)</p>", isHTML: true)
viewController.present(mailVC, …Run Code Online (Sandbox Code Playgroud) class-hierarchy messageui ios swift mfmailcomposeviewcontroller
自从我为新的iOS 5.0更新了XCode后,我的MailComposer函数中出现了警告.
MFMailComposeViewController *pickerZap = [[MFMailComposeViewController alloc] init];
pickerZap.mailComposeDelegate = self;
// warning: Assigning to 'id<MFMailComposeViewControllerDelegate>'
// from incompatible type 'Infocontroller *'
Run Code Online (Sandbox Code Playgroud)
MFMailComposeViewControllerDelegate发生了什么?我究竟做错了什么?
mfmailcomposeviewcontroller ×10
ios ×5
iphone ×5
objective-c ×4
email ×2
xcode ×2
3dtouch ×1
attachment ×1
html ×1
html-email ×1
ios5 ×1
ipad ×1
messageui ×1
swift ×1
swift2 ×1
video ×1