我正在尝试使用发送电子邮件选项设置应用.
我有这个代码:
import Foundation
import MessageUI
import UIKit
class emailClass: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if !MFMailComposeViewController.canSendMail() {
print("Mail services are not available")
return
}
sendEmail()
}
func sendEmail() {
let composeVC = MFMailComposeViewController()
composeVC.mailComposeDelegate = self
// Configure the fields of the interface.
composeVC.setToRecipients(["address@example.com"])
composeVC.setSubject("Hello!")
composeVC.setMessageBody("Hello this is my message body!", isHTML: false)
// Present the view controller modally.
self.present(composeVC, animated: true, completion: nil)
}
func mailComposeController(controller: MFMailComposeViewController,
didFinishWithResult result: MFMailComposeResult, error: NSError?) {
// Check …Run Code Online (Sandbox Code Playgroud) 我有一个视图控制器,以模态方式打开MFMailComposeViewController.当我尝试将邮件视图控制器的委托设置为父视图控制器时,我收到此警告:
Assigning to 'id<UINavigationControllerDelegate>' from incompatible
type 'MoreViewController *__strong'
Run Code Online (Sandbox Code Playgroud)
父视图控制器在其接口声明中肯定有MFMailComposeViewControllerDelegate,并且正在实现委托方法-mailComposeController: didFinishWithResult:error:,如下所示:
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSLog(@"Delegate called");
}
Run Code Online (Sandbox Code Playgroud)
我真的不明白为什么父视图控制器被识别为UINavigationControllerDelegate,因为我没有实现这些方法,也没有这样声明它.我不会那么担心它,但委托方法永远不会被调用,所以我猜这个"不匹配"是问题的一部分.
如果它有帮助,这就是我在邮件视图控制器中的方式viewDidLoad:
// MAIL
self.mail = [[MFMailComposeViewController alloc] init];
self.mail.delegate = self;
Run Code Online (Sandbox Code Playgroud)
提前感谢您的任何想法.
iphone objective-c messageui ios mfmailcomposeviewcontroller
我想实现一个iOS应用程序,它将使用SMS文本作为原始信息.我认为Apple不允许这样做.iOS应用程序可以读取/访问SMS文本吗?或者我们还有其他方法可以做同样的事情吗?
修改:我们可以读取未保存在SMS框中的服务消息,如余额消息吗?
我有一个Core Data对象Account,表示为以下的子类NSManagedObject:
@interface Account : NSManagedObject
Run Code Online (Sandbox Code Playgroud)
我的整个应用程序一直在发展很好,但是,当我添加MessageUI.framework所以我可以得到一个撰写电子邮件视图控制器,所有地狱都松了一口气.该应用程序链接和编译很好,运行得很好.直到,也就是说,我开始与之前工作的Account对象进行交互.然后,我开始得到这些:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '"Account" is not a subclass of NSManagedObject.'
*** First throw call stack:
(0x202b012 ... 0x2385)
libc++abi.dylib: terminate called throwing an exception
Run Code Online (Sandbox Code Playgroud)
其中一个特殊原因是:
// we need to insert a new account
Account *newAccount = [NSEntityDescription
insertNewObjectForEntityForName:[Account entityName]
inManagedObjectContext:self.managedObjectContext];
Run Code Online (Sandbox Code Playgroud)
现在,我猜测MessageUI.framework导致冲突有一些课,但我有几个问题:
MFMailComposeViewController,那么理论帐户应该不是MFAccount吗?#import <MessageUI/MessageUI.h>或稍微紧一些#import <MessageUI/MFMailComposeViewController.h>,后者我检查过并没有看到任何定义Account,所以我不确定为什么甚至会加载可能的冲突.由于adMob包的最后一个版本,我已将MessageUI框架添加到我的项目中.由于我希望将我的应用程序部署到2.x OS设备,我建议使用弱链接的MessageUI.
如果我为iPhone设备3.0构建,它工作正常.
如果我为iPhone设备2.2.1构建,我收到一个链接错误:"ld:框架未找到MessageUI"
我哪里错了?
我是一名软件开发人员,我正在为电子邮件制作应用程序,我有以下代码:
// Header file
// importing the MessageUI framework
#import <MessageUI/MessageUI.h>
// adding the delegate functionality to the class (<MFMailComposeViewControllerDelegate>)
@interface TutorialProjectViewController : UIViewController <MFMailComposeViewControllerDelegate> {
}
- (IBAction)pressTheMailButtonDudeFunction:(id)sender
// Implementation file
- (IBAction)pressTheMailButtonDudeFunction:(id)sender {
// allocatind new message composer window
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
// setting a delegate method to "self"
mc.mailComposeDelegate = self;
// pre-populating the message subject
[mc setSubject:@"Send me a message"];
// adding content of the message as a plain text
[mc setMessageBody:@"Send me …Run Code Online (Sandbox Code Playgroud) iphone objective-c messageui ipad mfmailcomposeviewcontroller
我有一个仅限iOS 7的应用程序,它使用UIAppearance来为整个应用程序中的UINavigationBar设置样式.
我的AppDelegate中有以下代码:
[[UINavigationBar appearance] setBackgroundImage:redImage forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setBackgroundImage:blueImage forBarMetrics:UIBarMetricsDefault];
Run Code Online (Sandbox Code Playgroud)
但是,MFMailComposeViewController会出现redImage背景!
文档说明如下:
要点:此类的视图层次结构是私有的,您不能修改它.但是,您可以使用UIAppearance协议自定义实例的外观.
所以没有理由说上面的内容不起作用,我100%肯定redImage并且blueImage是不同颜色的图像.
还有其他人遇到过这个问题吗?我猜它是iOS 7中的一个错误但我没有时间检查iOS 6(我通过使用iPad 4得到这些结果).
有没有人对正确的方法有任何想法?这里有一个类似问题的答案,但它是如此令人费解,我无法想象它是对的.弹出此模态视图时,必须有一种更简单的方法来显示键盘.对?
在UIViewControllerSwift 的正常情况下,我使用此代码发送邮件。
let mailComposeViewController = configuredMailComposeViewController()
mailComposeViewController.navigationItem.leftBarButtonItem?.style = .plain
mailComposeViewController.navigationItem.rightBarButtonItem?.style = .plain
mailComposeViewController.navigationBar.tintColor = UIColor.white
if MFMailComposeViewController.canSendMail() {
self.present(mailComposeViewController, animated: true, completion: nil)
} else {
self.showSendMailErrorAlert()
}
Run Code Online (Sandbox Code Playgroud)
如何在SwiftUI中实现相同目标?
我需要使用UIViewControllerRepresentable吗?
if([MFMessageComposeViewController canSendText])
{
MFMessageComposeViewController *sms_message_vc = [[MFMessageComposeViewController alloc] init];
sms_message_vc.body = text;
sms_message_vc.recipients = recipients;
sms_message_vc.messageComposeDelegate = self;
[self presentModalViewController:sms_message_vc animated:FALSE];
[[UIApplication sharedApplication] setStatusBarHidden:TRUE];
[sms_message_vc release];
}
Run Code Online (Sandbox Code Playgroud)
执行此操作时,在实际显示撰写视图之前会有几秒钟的延迟.造成这种情况的原因是什么以及如何消除延迟?
编辑1:澄清:制作sms_message_vc和ivar没有帮助,因为该...alloc] init]过程将挂起UI几秒钟,无论它在哪里.
编辑2:尝试GCD(具有不同的优先级)以尝试同时运行初始化.没有帮助:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, (unsigned long)NULL), ^(void){
sms_message_vc = [[MFMessageComposeViewController alloc] init];
sms_message_vc.messageComposeDelegate = self;
});
Run Code Online (Sandbox Code Playgroud) messageui ×10
iphone ×7
ios ×6
objective-c ×4
mfmailcomposeviewcontroller ×3
ipad ×2
swift ×2
frameworks ×1
ios7 ×1
linker ×1
sms ×1
swift3 ×1
swiftui ×1
uiappearance ×1
weak-linking ×1
xcode ×1