2017-02-12 1 views
1

사용자가 전자 메일을 보내고 sms.MsMailComposeViewController를 사용하여 보낼 수있는 iOS 응용 프로그램에서 작업 중입니다. & MFMessageComposeViewController는 전자 메일과 SMS를 보내기 위해 사용하지만 때로는 취소 및 보내기 단추가 작곡가 위에 나타나고 언젠가는 나타나지 않습니다. 전혀 나타나지 않습니다. 이 문제는 무작위이며 알아 내려고 노력했습니다. 어떤 도움이라도 대단히 감사하겠습니다. 내가 헤더 파일 내의 ViewController에 MFMailComposeViewControllerDelegate을 구현 한MFMailComposeViewController에서 단추를 놓치지 않고 보내십시오. iOS

MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init]; 
    mail.mailComposeDelegate = self; 
    [mail setSubject:Email_Subject]; 
    [mail setMessageBody:Share_Message isHTML:NO]; 
    [mail setToRecipients:@[@""]]; 
    [self presentViewController:mail animated:YES completion:NULL]; 

코드입니다.

+0

당신이 장치 또는 시뮬레이터에서 확인됩니다

[UINavigationBar appearance].tintColor = appleBlueTintColor; 

정말이 모든의 비밀 소스입니다 : 라인이 있습니다? – HardikDG

+0

iPhone 6에서 테스트 중입니다. – iOSGeek

+0

프레젠테이션 또는 레이아웃 문제와 같은 소리입니다. AutoLayout을 사용하고 있습니까? 내비게이션 막대가없는 공간이 있습니까? 아니면 막대가 화면 상단보다 위에있는 것처럼 보입니까? –

답변

0

오케이, 나는 마침내 이것에 대한 견해를 가지고 있습니다. 내 문제는 내 애플 대리자 (스위프트)에서 탐색 막대 색상을 변경 내에서 부분적으로 막아야 :이 때문에

UINavigationBar.appearance().barTintColor = UIColor.black 
    UIApplication.shared.statusBarStyle = .lightContent 

    // To get my hamburger menu white colored 
    UINavigationBar.appearance().tintColor = UIColor.white 

하고, 확대 된 모드와 어떤 상호 작용은 가끔 얻을 것 (위 내 의견을 참조) 취소/보내기 단추가 내 메일 컨트롤러에서 흰색으로 설정됩니다.

enter image description here

내가 당신에게 내 수업 (목적 C)을 보여주지 날이 문제의 문제를 해결하기 위해 지금 작동하는 메일 컨트롤러를 표시하는이처럼.

#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 = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    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 (![MFMailComposeViewController canSendMail]) { 
     NSString *title = @"Sorry, the app isn't allowed to send email."; 
     NSString *message = @"Have you configured this device to send email?"; 
     UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; 
     [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; 
     [theParent presentViewController:alert animated:YES completion:nil]; 
     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 = [UINavigationBar appearance].barTintColor; 
    self.previousTintColor = [UINavigationBar appearance].tintColor; 

    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]]; 

    // I got this color from the digital color meter-- this is what it is supposed to be on the Cancel/Send buttons. 
    UIColor *appleBlueTintColor = [UIColor colorWithRed:31.0/255.0 green:134.0/255.0 blue:254.0/255.0 alpha:1.0]; 
    [UINavigationBar appearance].tintColor = appleBlueTintColor; 

    self = [super init]; 
    if (self) { 
     self.mailComposeDelegate = self; 
     self.myParent = theParent; 
    } 

    return self; 
} 

- (void) show { 
    [self.myParent presentViewController:self animated:YES completion:^{ 
     [[UINavigationBar appearance] setBarTintColor: self.previousBarTintColor]; 
     [UINavigationBar appearance].tintColor = self.previousTintColor; 
    }]; 
} 

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { 
    [self.myParent dismissViewControllerAnimated:YES completion:nil]; 
} 

+ (NSString *) getVersionDetailsFor: (NSString *) appName; 
{ 
    NSMutableString *message = [NSMutableString string]; 
    [message appendString:@"\n\n\n--------------\n"]; 
    [message appendFormat:@"iOS version: %@\n", [[UIDevice currentDevice] systemVersion]]; 
    [message appendFormat:@"%@ version: %@ (%@)\n", appName, 
    [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], 
    [[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleVersion"]]; 
    [message appendFormat:@"Hardware: %@\n", [self machineName]]; 

    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 
관련 문제