MFMessageComposeViewController使消息体重复两次

时间:2014-04-14 10:46:51

标签: ios ios7 mfmailcomposeviewcontroller

使用以下代码使用MFMessageComposeViewController设置应用程序内SMS消息时:

if([MFMessageComposeViewController canSendText])
{
    // Add Cocos view & stop anims
    [[[CCDirector sharedDirector] view] addSubview:self.view];
    [[CCDirector sharedDirector] pause];
    [[CCDirector sharedDirector] stopAnimation];

    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];

    controller.body = @"TEST";
    controller.recipients = nil;
    controller.messageComposeDelegate = self;

    // Cocos window view present
    [[[[CCDirector sharedDirector] view] window] addSubview:controller.view];
    [[CCDirector sharedDirector] presentViewController:controller animated:YES completion:^{NSLog(@"test open");}];


}

视图显示正确,但邮件正文文本显示两次。在可编辑的文本字段中,它具有“TEST”,然后在下一行再次显示“TEST”。

我尝试添加标题并使用各种不同的消息,但我总是让消息正文出现两次。我还检查了代码是否只被多次调用,但事实并非如此。

任何想法?

(Xcode 5.0.1,iPhoneOS 7.0 SDK,在iPhone 5上测试)

1 个答案:

答案 0 :(得分:0)

对于遇到这种情况的其他人,我发现在设置正文文本之前将控制器视图添加到窗口修复了问题。

像这样:

if([MFMessageComposeViewController canSendText])
{
    [[CCDirector sharedDirector] pause];
    [[CCDirector sharedDirector] stopAnimation];

    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];

    // ** Add the view BEFORE setting the body text... **
    [[[[CCDirector sharedDirector] view] window] addSubview:controller.view];

    [controller setRecipients:nil];
    controller.messageComposeDelegate = self;
    [controller setBody:message];

    [[CCDirector sharedDirector] presentModalViewController:controller animated:YES ];
}

使用此代码,正文文本不会在短信中重复。