我有一个应用程序,在我的信息列表中将其设置为“横向左”,“横向右”和“人像”。但是,对于我的所有视图控制器,我通常都以横向模式运行,并且我已经设置了
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;}
除了视图控制器外,我有一个希望允许用户发送电子邮件的按钮。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{return YES;}
当我尝试发送电子邮件时,我的应用程序崩溃了。它在我的iPad上正常工作。这是我发送电子邮件的代码。
- (IBAction)sendEmail:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:@"HI!"];
UIImage *myImage = [UIImage imageNamed:@"myPicture.png"];
NSData *imageData = UIImagePNGRepresentation(myImage);
[mailComposer addAttachmentData:imageData mimeType:@"image/png" fileName:@"FullTitle.png"];
NSString *emailBody = @"Hi there!!";
[mailComposer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
message:@"Your device does not support email function"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued.");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved: you saved the email message in the drafts folder.");
break;
case MFMailComposeResultSent:
NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send.");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
break;
default:
NSLog(@"Mail not sent.");
break;
}
[self dismissModalViewControllerAnimated:YES];
}
我不确定,但是我可能以某种方式将自己锁定在横向模式,因此当我想发送电子邮件时,iPhone希望旋转到人像,但似乎不允许这样做。我在控制台中没有看到任何错误消息。
在此先感谢您的帮助。
最佳答案
您的应用程序可能内存不足,这是由调用UIImagePNGRepresentation()引起的。创建NSData时,此函数将整个映像复制到内存中。图像越大,使用的内存越多。该问题的可能解决方案是使用UIImageJPEGRepresentation()而不是UIImagePNGRepresentation()并将诸如0.6之类的内容传递给compressionQuality参数。可以在Apple文档中找到更多信息:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UIImageJPEGRepresentation