2017-02-12 10 views
1

ユーザーがメールを送信してsms.Iを送信できるMFMailComposeViewController & MFMessageComposeViewControllerを送信してメールとSMSを送信するiOSアプリで作業していますが、全く現れません。この問題はランダムで、私は把握するために多くを試しました。どんな助けでも大歓迎です。 コードキャンセルボタンを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]; 

私は、ヘッダファイルに私のViewControllerでMFMailComposeViewControllerDelegateを実装しています。

+0

あなたは、デバイスまたはシミュレータでチェックしていますか? – HardikDG

+0

iPhone 6でテスト中 – iOSGeek

+0

プレゼンテーションやレイアウトの問題のようなサウンドです。 AutoLayoutを使用していますか?ナビゲーションバーがないスペースがあるか、バーが画面の上にあるように見えますか? –

答えて

0

[OK]を、私は最後にこれにいくつかの牽引力を持っています。時々私は得るだろう、(上記の私のコメントを参照してください)

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

私はあなたに私はこの質問で問題を解決するために機能するようになりましたメールコントローラを表示私のクラス(のObjective C)を紹介します。

[UINavigationBar appearance].tintColor = appleBlueTintColor; 

本当にこれがすべてでは秘密のソースです::行があることに注意してください

#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 
関連する問題