Thursday 3 January 2013

presentViewController:animated:completion: is available on iOS5 and above only, hence you get that crash.

 presentViewController:animated:completion: is available on iOS5 and above only, hence you get that crash.


Change the last part to:


if ([MFMailComposeViewController canSendMail]) 
        {
            UIImage *tempImageSave=[self captureView];
            //                imgBackBoard.image = [self captureView];
            //                [imgBackBoard.image retain];
            MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
            NSString *mailBody = @"New Image Of Retreat Caravans Posted By Paras";
            
            NSData *imageData = UIImagePNGRepresentation(tempImageSave);
            [mailComposeViewController addAttachmentData:imageData mimeType:@"image/png" fileName:@"Testing"];
            [mailComposeViewController setMessageBody:mailBody isHTML:NO];
            mailComposeViewController.mailComposeDelegate = self;
            if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
            {   //yes->so do it!
                [self presentViewController:mailComposeViewController animated:YES completion:NULL];
            }
            else
            {   //nope->we seem to be running on something prior to iOS5, do it the old way!
                [self presentModalViewController:mailComposeViewController animated:YES];
            }
//            [self presentViewController:mailComposeViewController animated:YES completion:nil];
        } 
        else 
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"e-Mail Sending Alert"
                                                            message:@"You can't send a mail"
                                                           delegate:nil
                                                  cancelButtonTitle:@"OK" 
                                                  otherButtonTitles:nil];
            [alert show];
            [alert release];
        }

Also dissmis like above..
For EX..


if([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)])
        [self dismissViewControllerAnimated:YES completion:nil];
    else
        [self dismissModalViewControllerAnimated:YES];



This will first check if the new way of presenting a viewController is supported. For making sure that this works fine in the future, as presentModalViewController: is marked as being deprecated, we only use that option if the new way is not available.

No comments:

Post a Comment