36

私は長い間遭遇した中で最も奇妙な問題を抱えています...そして私はアイデアを使い果たしました.

そのため、UIButton をタップすると起動される MFMailComposeViewController があり、メール コンポーザ ビューを正常に起動しています。私が割り当てた件名が表示されますが、to: または body フィールドが入力される前に、ウィンドウが点滅して消えます。次のエラーがスローされます。

viewServiceDidTerminateWithError: エラー Domain=XPCObjectsErrorDomain Code=2 「操作を完了できませんでした。(XPCObjectsErrorDomain エラー 2.)」

ここがクレイジーな部分です。MFMailComposeViewController も使用する別のアプリに切り替えてそのアプリを起動してから、自分のアプリに戻ってメール コンポーザを再度起動すると、問題なく動作します。私はそれを説明することはできません。

これは、 iPhone 5 以外のiOS 6 を実行している電話でのみ問題になるようです。

私は周りを検索しましたが、この同じ問題を経験した人を他に見つけることができないようです. 誰にも何か提案がありますか?

MessageUI.framework をリンクしましたが、これがシミュレーターまたはデバイスで機能していないこともわかりましたが、Security.framework もリンクするとシミュレーターで機能し始めましたが、まだ機能しませんデバイス上。

MFMailComposeViewController を起動するための私のコードは次のとおりです。

.h ファイル内

#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>

.m ファイル内

-(void)displayComposerSheet {
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"Support Request"];

// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"support@domain.com"];

[picker setToRecipients:toRecipients];

// Fill out the email body text
NSString *emailBody = @"\n\nEmail from iOS";
[picker setMessageBody:emailBody isHTML:NO];

[self presentModalViewController:picker animated:YES];
}


// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation. 
- (void)mailComposeController:(MFMailComposeViewController*)controller     didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{

    [self dismissModalViewControllerAnimated:YES];
}

更新: UINavigationBar の外観デリゲートに渡した設定に絞り込んだと思います。カスタムフォントを使用していますが、それをオフにすると機能するようです...しかし、なぜiPhone5で機能するのでしょうか...

4

9 に答える 9

16

UITextAttributeFontのカスタムフォントをUINavigationBarアピアランスプロキシのtitleTestAttributesに設定すると、OPとMightlyLeaderが識別したときにバグが発生します。

回避策コード:

// remove the custom nav bar font
NSMutableDictionary* navBarTitleAttributes = [[UINavigationBar appearance] titleTextAttributes].mutableCopy;
UIFont* navBarTitleFont = navBarTitleAttributes[UITextAttributeFont];
navBarTitleAttributes[UITextAttributeFont] = [UIFont systemFontOfSize:navBarTitleFont.pointSize];
[[UINavigationBar appearance] setTitleTextAttributes:navBarTitleAttributes];

// set up and present the MFMailComposeViewController
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:emailInfo[@"subject"]];
[mailComposer setMessageBody:emailInfo[@"message"] isHTML:YES];
mailComposer.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentViewController:mailComposer animated:YES completion:^{

    // add the custom navbar font back
    navBarTitleAttributes[UITextAttributeFont] = navBarTitleFont;
    [[UINavigationBar appearance] setTitleTextAttributes:navBarTitleAttributes];
}];
于 2013-01-30T03:17:40.027 に答える
12

この問題は、私が取り組んでいるプロジェクトで最近発生しました。上記の回避策があまり好きではなかったので、代わりに次の(おそらく少しクリーンな)回避策を作成しました。

// Implement the custom font for all UINavigationBar items
[[UINavigationBar appearance] setTitleTextAttributes:
@{
    UITextAttributeFont : [UIFont custom_superAwesomeFontWithSize:16.0f],
}];


// Disable the custom font when the NavigationBar is presented in a MFMailComposeViewController
[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setTitleTextAttributes:
 @{
    UITextAttributeFont : [UIFont boldSystemFontOfSize:14.0f],
 }];
于 2013-08-08T15:34:38.933 に答える
9

同じ問題がありました。タイトル バーのテキスト属性をカスタム フォントに設定しました。カスタム フォントの指定を削除すると (ただし、他のすべての属性はカスタム値のままにしておきます)、問題は解消されました。

私の診断では、カスタム フォントの読み込みに時間がかかりすぎて、待機フェンスからのタイムアウトがトリガーされます。

于 2012-11-26T15:55:18.417 に答える
3

これを ivar にします。

MFMailComposeViewController *picker 

次に、この行の後:

[self dismissModalViewControllerAnimated:YES];

これを追加:

dispatch_async(dispatch_get_main_queue(), ^{ picker = nil; });

ピッカーのリリースが次のランループ サイクルまで発生しないようにします。

于 2012-09-27T17:08:15.010 に答える
1

dberwick の回避策はうまくいきます。コンポーザーは自動的にキャンセルされなくなり、メッセージ コンポーザーを閉じるとカスタム ナビゲーション バーのタイトル フォント設定が復元されます、メッセージ コンポーザー自体にカスタム フォントは表示されません。

回避策によって実際のコードが肥大化するのが嫌だったので、ほとんどを移動する簡単な方法を次に示します。

- (void)presentMessageCommposer
    void (^workaroundRestoreFont)(void) = [self ym__workaroundCustomFontInMessageComposer];

    MFMailComposeViewController *mailComposeVC = [MFMailComposeViewController new];
    // ... set up the composer: message body, subject, etc ...
    [self presentViewController:mailComposeVC animated:YES completion:workaroundRestoreFont];
}


// ugly workaround stuff
// move this to the bottom of your class, collapse it, or put it in a category
- (void (^)(void))ym__workaroundCustomFontInMessageComposer
{
    // Bug http://openradar.appspot.com/13422715
    // remove the custom nav bar font
    NSMutableDictionary* navBarTitleAttributes = [[UINavigationBar appearance] titleTextAttributes].mutableCopy;
    UIFont *navBarTitleFont = navBarTitleAttributes[UITextAttributeFont];
    navBarTitleAttributes[UITextAttributeFont] = [UIFont systemFontOfSize:navBarTitleFont.pointSize];
    [[UINavigationBar appearance] setTitleTextAttributes:navBarTitleAttributes];

    return ^{
        // add the custom navbar font back
        NSMutableDictionary* navBarTitleAttributes = [[UINavigationBar appearance] titleTextAttributes].mutableCopy;
        navBarTitleAttributes[UITextAttributeFont] = navBarTitleFont;
        [[UINavigationBar appearance] setTitleTextAttributes:navBarTitleAttributes];
    };
}

(これは実際には dberwick の回答に対するコメントである必要がありますが、これほど多くのコードは許可されません。)

于 2013-03-15T22:42:21.567 に答える
0

コンポーザーをiVarとして追加するだけで問題が解決しました。

MFMailComposeViewController *emailComposer;

于 2015-11-16T16:35:09.423 に答える
-2

私が読んだことから、iOS 6では、これは非推奨です:

[self presentModalViewController:picker animated:YES];

彼らは以下を使用することを提案しています:

[self presentViewController:picker animated:YES completion:nil];

対になった (でdidFinishWithResult)

[[controller presentingViewController] dismissViewControllerAnimated:YES completion:nil];

残念ながら、これはシミュレーターでは断続的にしか機能しません...しかし、時々機能します!

于 2013-01-24T20:09:21.503 に答える