我在设置UIViewController的方向时遇到问题。
我制作了一个脚本,用于在我的应用程序中统一使用消息UI。
iOS7之前没有问题,但它出现在iOS8上。
应用程序的初始方向是landscapeRight,并且在应用程序期间没有任何更改。 但是,如果我调用SMS消息UI,则UI具有纵向方向。其他(如状态栏和键盘)都只是版权所有的消息用户界面。
我如何解决这个问题,我通过谷歌搜索搜索这个问题,但我找不到。
这是我的代码:
#import <UIKit/UIKit.h>
#import <MessageUI/MFMessageComposeViewController.h>
#import "UnityAppController.h"
extern UIViewController *UnityGetGLViewController();
@interface SendSMSViewController : UIViewController
<MFMessageComposeViewControllerDelegate>
{
UIWindow *uiwindow;
}
@end
@implementation SendSMSViewController
-(void)dealloc
{
[super dealloc];
}
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller
didFinishWithResult:(MessageComposeResult)result{
switch(result){
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
NSLog(@"Error occured");
break;
case MessageComposeResultSent:
NSLog(@"Sent");
break;
default:
NSLog(@"Default");
break;
}
[self dismissViewControllerAnimated: YES completion:nil];
[uiwindow release];
}
-(void)sendSMS:(NSString *)text rootwindow:(UIWindow *)window{
uiwindow = window;
MFMessageComposeViewController *controller =
[[[MFMessageComposeViewController alloc] init] autorelease];
if([MFMessageComposeViewController canSendText]){
controller.body = text;
controller.messageComposeDelegate = self;
[self presentViewController:controller
animated:YES completion:nil];
}
}
@end
extern "C"{
void _sendSMS(const char* body);
}
void _sendSMS(const char* body){
NSString *strBody = [NSString stringWithUTF8String: body];
SendSMSViewController *viewController = nil;
viewController = [[SendSMSViewController alloc] init];
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] nativeBounds]];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
[window.rootViewController presentViewController:viewController animated:YES completion:nil];
[viewController sendSMS:strBody rootwindow:window];
}
感谢。