ios - MFMailComposeViewController iOS 上缺少取消和发送按钮
<p><p>我正在开发一个 iOS 应用程序,用户可以在其中发送电子邮件和发送短信。我正在使用 MFMailComposeViewController 和 MFMessageComposeViewController 发送电子邮件和短信,但有时取消和发送按钮会出现在 Composer 上,有时它根本不会出现。这个问题是随机的,我已经尝试了很多。任何帮助将不胜感激。
<strong>代码</strong></p>
<pre><code>MFMailComposeViewController *mail = [ init];
mail.mailComposeDelegate = self;
;
;
];
;
</code></pre>
<p>我已经在我的 viewController 的头文件中实现了 MFMailComposeViewControllerDelegate。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>好的,我终于对此有了一些了解。我的问题部分源于我在应用程序委托(delegate) (Swift) 中更改导航栏颜色:</p>
<pre><code> UINavigationBar.appearance().barTintColor = UIColor.black
UIApplication.shared.statusBarStyle = .lightContent
// To get my hamburger menu white colored
UINavigationBar.appearance().tintColor = UIColor.white
</code></pre>
<p>由于这一点,以及与缩放模式的一些交互(参见我上面的评论),有时我会在我的邮件 Controller 中将取消/发送按钮设置为白色。像这样:</p>
<p> <a href="/image/68DdQ.png" rel="noreferrer noopener nofollow"><img src="/image/68DdQ.png" alt="enter image description here"/></a> </p>
<p>我将向您展示我的类(class)( Objective-C ),它显示了邮件 Controller ,现在它可以帮助我解决这个问题中的问题。注意这一行:</p>
<pre><code>.tintColor = appleBlueTintColor;
</code></pre>
<p>真的是这一切的秘诀:</p>
<pre><code>#import <MessageUI/MessageUI.h>
@interface SendEmail : MFMailComposeViewController
// Returns nil if can't send email on this device. Displays an alert before returning in this case.
- (id) initWithParentViewController: (UIViewController *) parent;
// Show the email composer.
- (void) show;
// Message to append to the bottom of support emails. The string doesn't contain HTML.
+ (NSString *) getVersionDetailsFor: (NSString *) appName;
@end
@interface SendEmail ()<MFMailComposeViewControllerDelegate>
@property (nonatomic, weak) UIViewController *myParent;
@property (nonatomic, strong) UIColor *previousBarTintColor;
@property (nonatomic, strong) UIColor *previousTintColor;
@end
#import "SendEmail.h"
#import <sys/utsname.h>
@implementation SendEmail
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = ;
if (self) {
// Custom initialization
}
return self;
}
// Using this init method depends on the `show` method being called immediately after-- to reset the nav bar colors back to what they were originally.
- (id) initWithParentViewController: (UIViewController *) theParent {
if (!) {
NSString *title = @"Sorry, the app isn't allowed to send email.";
NSString *message = @"Have you configured this device to send email?";
UIAlertController *alert = ;
];
;
return nil;
}
// The default app nav bar color is black-- and that looks bad on the mail VC. Need to change and then set back both the barTintColor and the tintColor (in the `show` method).
self.previousBarTintColor = .barTintColor;
self.previousTintColor = .tintColor;
[ setBarTintColor:];
// I got this color from the digital color meter-- this is what it is supposed to be on the Cancel/Send buttons.
UIColor *appleBlueTintColor = ;
.tintColor = appleBlueTintColor;
self = ;
if (self) {
self.mailComposeDelegate = self;
self.myParent = theParent;
}
return self;
}
- (void) show {
[self.myParent presentViewController:self animated:YES completion:^{
[ setBarTintColor: self.previousBarTintColor];
.tintColor = self.previousTintColor;
}];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
;
}
+ (NSString *) getVersionDetailsFor: (NSString *) appName;
{
NSMutableString *message = ;
;
systemVersion]];
[message appendFormat:@"%@ version: %@ (%@)\n", appName,
[ objectForInfoDictionaryKey:@"CFBundleShortVersionString"],
[objectForInfoDictionaryKey:@"CFBundleVersion"]];
];
return message;
}
// See http://stackoverflow.com/questions/11197509/ios-iphone-get-device-model-and-make
+ (NSString *) machineName;
{
struct utsname systemInfo;
uname(&systemInfo);
return [NSString stringWithCString:systemInfo.machine
encoding:NSUTF8StringEncoding];
}
@end
</code></pre></p>
<p style="font-size: 20px;">关于ios - MFMailComposeViewController iOS 上缺少取消和发送按钮,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42189722/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42189722/
</a>
</p>
页:
[1]