add screenshot of MKMapview to AlertView is not working

129 Views Asked by At

I have the following code to take a screenshot of the mapview and view this screenshot in the alert view. I can't find where the problem is!

here is the alertview code :

UIAlertView *alertBox=[[UIAlertView alloc]initWithTitle:@"image Info." message:@"here is your image" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];
[imageView setImage:[self renderToImage]];

[alertBox addSubview:imageView];
[alertBox show];

and this is the method's code :

 - (UIImage*) renderToImage{
UIGraphicsBeginImageContextWithOptions(mapMKMapView.frame.size, NO, 0.0);
[mapMKMapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
 }

any help will be great. Thanks in advance!

1

There are 1 best solutions below

1
On

Adding some controls to UIAlertView was deprecated in iOS7 using addSubview method. So you need to test your app in two different targets (1. iOS7 and 2. < iOS7) to check whether problem is in code or because of iOS versions.