应用程序崩溃取消Message Composer或Mail Composer视图

时间:2017-06-01 11:09:29

标签: ios objective-c xcode

我的应用是横向模式。我只使用以下代码行呈现活动视图控制器: -

 NSArray *shrArr = [NSArray arrayWithObjects:[NSString stringWithFormat:@"%@", KHL_SHARE_TEXT], nil];
UIActivityViewController *shareUIAVC = [[UIActivityViewController alloc] initWithActivityItems: shrArr applicationActivities: nil];
if([shareUIAVC respondsToSelector:@selector(setValue:forKey:)])
{
    [shareUIAVC setValue:KHL_SHARE_MAIL_TEXT forKey:@"subject"];
}

if([shareUIAVC respondsToSelector:@selector(popoverPresentationController)])
{
    shareUIAVC.popoverPresentationController.sourceView = self.menuButton;
    shareUIAVC.popoverPresentationController.sourceRect = self.menuButton.bounds;
}
[self presentViewController:shareUIAVC animated: YES completion: nil];

活动视图控制器在横向打开,在选择邮件或邮件以及发送或取消邮件或邮件编辑器时,应用程序崩溃并显示以下日志。

*由于未捕获的异常终止应用' UIApplicationInvalidInterfaceOrientation',原因:' preferredInterfaceOrientationForPresentation'(7)'必须符合支持的界面方向:' landscapeLeft,landscapeRight'!' * 第一次抛出调用堆栈: (0x186f991b8 0x1859d055c 0x186f99100 0x18cf44670 0x18d810428 0x18d19abf0 0x18d1be6c8 0x18cf7b1bc 0x18cf21f14 0x18d1bd920 0x18cf21a48 0x18d7f672c 0x18d7f6a64 0x18d067bdc 0x18d7d5ad4 0x1974b498c 0x1974cbad8 0x186f9f150 0x186e91eac 0x188b6f92c 0x188b6f798 0x188b48058 0x18d0d1684 0x18d126664 0x18a293e10 0x18a26b4c4 0x18a292a68 0x18a293488 0x186f460c0 0x186f43cf0 0x186f44180 0x186e722b8 0x188926198 0x18ceb97fc 0x18ceb4534 0x100143930 0x185e555b8) libc ++ abi.dylib:以NSException类型的未捕获异常终止 2017-06-01 16:36:17.423693

根据各种来源的建议,我也添加了以下代码,但这确实有效

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}

-(BOOL)shouldAutorotate
{
return NO;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}

提前致谢!

1 个答案:

答案 0 :(得分:0)

在appdelegate中添加此内容

 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
    {
        //self.isMailController enable while activityViewcontroller appears and disable while it dissmissed.
        if(self.isMailController){
// you can check multiple viewcontroller
            return UIInterfaceOrientationMaskPortrait; // if your mail viewcontroller it will display on portrait
        }
        return UIInterfaceOrientationMaskLandscape;
    }