当我在 IOS 6 模拟器或具有相同 IOS 的设备上运行应用程序时,我正在使用 xcode 5.0,如果我使用 IOS 7 模拟器运行或设备崩溃并出现以下错误:
2013-10-02 11:01:48.992 KLUSCIENCE3U04[1146:a0b] -[__NSArrayM length]: unrecognized selector sent to instance 0x17071970
2013-10-02 11:01:48.994 KLUSCIENCE3U04[1146:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0x17071970'
*** First throw call stack:
(
0 CoreFoundation 0x03e9f5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0277c8b6 objc_exception_throw + 44
2 CoreFoundation 0x03f3c903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x03e8f90b ___forwarding___ + 1019
4 CoreFoundation 0x03e8f4ee _CF_forwarding_prep_0 + 14
5 CoreFoundation 0x03e1f9cc CFStringGetLength + 140
6 CoreFoundation 0x03e23491 CFStringAppend + 177
7 CoreFoundation 0x03e1de73 __CFStringAppendFormatCore + 8611
8 CoreFoundation 0x03e5e9b4 _CFStringCreateWithFormatAndArgumentsAux + 116
9 Foundation 0x01f148d0 -[NSPlaceholderString initWithFormat:locale:arguments:] + 143
10 Foundation 0x01f1594d +[NSString stringWithFormat:] + 88
11 UIKit 0x0099a8c4 -[UIViewController presentViewController:withTransition:completion:] + 2649
12 CoreFoundation 0x03e93d1d __invoking___ + 29
13 CoreFoundation 0x03e93c2a -[NSInvocation invoke] + 362
14 UIKit 0x0098a25f -[_UIDelayedPresentationContext finishDelayedPresentation:] + 238
15 UIKit 0x00999ae6 -[UIViewController _endDelayingPresentation] + 104
16 MessageUI 0x00762e12 -[MFMailComposeInternalViewController _endDelayingCompositionPresentation] + 193
17 MessageUI 0x007637fd -[MFMailComposeInternalViewController _finishServiceViewControllerRequestWithSuccess:] + 300
18 MessageUI 0x00763601 __68-[MFMailComposeInternalViewController _configureRemoteViewContoller]_block_invoke + 205
19 MessageUI 0x0076367b __68-[MFMailComposeInternalViewController _configureRemoteViewContoller]_block_invoke184 + 26
20 CoreFoundation 0x03e93d1d __invoking___ + 29
21 CoreFoundation 0x03e93c2a -[NSInvocation invoke] + 362
22 UIKit 0x00e709ef __63-[_UIViewServiceInterface connection:handleInvocation:isReply:]_block_invoke + 36
23 libdispatch.dylib 0x02a7f818 _dispatch_call_block_and_release + 15
24 libdispatch.dylib 0x02a944b0 _dispatch_client_callout + 14
25 libdispatch.dylib 0x02a82766 _dispatch_main_queue_callback_4CF + 340
26 CoreFoundation 0x03f04a5e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
27 CoreFoundation 0x03e4572b __CFRunLoopRun + 1963
28 CoreFoundation 0x03e44b33 CFRunLoopRunSpecific + 467
29 CoreFoundation 0x03e4494b CFRunLoopRunInMode + 123
30 GraphicsServices 0x038279d7 GSEventRunModal + 192
31 GraphicsServices 0x038277fe GSEventRun + 104
32 UIKit 0x0087c94b UIApplicationMain + 1225
33 KLUSCIENCE3U04 0x000b86b6 main + 134
34 KLUSCIENCE3U04 0x00002b15 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
这是代码:
-(void)sendEmail
{
@try {
NSString *imageToAttach1,*imageToAttach2, *imageName;
NSInteger i = carousel.currentItemIndex;
imageToAttach1 = [images objectAtIndex:i];
imageToAttach2 = [description objectAtIndex:i];
// Attach image1 to the email
imageName = [imageToAttach1 substringToIndex:[imageToAttach1 length]-4];
NSString *imagePath = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
NSData *imageData = [NSData dataWithContentsOfFile:imagePath];
// Attach image2 to the email
imageName = [imageToAttach2 substringToIndex:[imageToAttach2 length]-4];
NSString *imagePath2 = [[NSBundle mainBundle] pathForResource:imageName ofType:@"png"];
NSData *imageData2 = [NSData dataWithContentsOfFile:imagePath2];
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"KLU Glossary"];
[picker addAttachmentData:imageData mimeType:@"image/png" fileName:imageToAttach1];
[picker addAttachmentData:imageData2 mimeType:@"image/png" fileName:imageToAttach2];
[picker setMessageBody:@"Glossary by KLU" isHTML:NO];
picker.navigationBar.barStyle = UIBarStyleBlack;
[self presentViewController:picker animated:YES completion:NULL];
[picker release];
}
}
@catch (NSException *exception) {
NSString *error = [[NSString alloc] initWithFormat:@"%@: %@",[exception name], [exception reason]];
NSLog(@"Error %@",error);
}
}
-(void) mailComposeController: (MFMailComposeViewController*)controller didFinishWithResult: (MFMailComposeResult)result error:(NSError*)error
{
switch (result)
{
case MFMailComposeResultCancelled:
break;
case MFMailComposeResultSaved:
break;
case MFMailComposeResultSent:
break;
case MFMailComposeResultFailed:
break;
default:
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Email" message:@"Sending Failed – Unknown Error "
delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
[alert release];
}
break;
}
[self dismissViewControllerAnimated:YES completion:NULL];
}