Pregunta

I have a MKMapView and I would like to take a screenshot of it and share it to a social network, for example to Facebook. I've found a nice way to make the screenshot, using MKMapSnapshotter (which is available starting with iOS 7), but my question is: Am I able to share a screenshot of MKMapView? Does Apple allow this?

I found this similar question, but there is not given any clear answer.

¿Fue útil?

Solución

Try Google Maps SDK for iOS: Documentation

And to make the screenshot use the following code:

CGRect rect = [captureView bounds];
UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
CGContextRef context = UIGraphicsGetCurrentContext();
[captureView.layer renderInContext:context];   
UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

Otros consejos

Yes of course, why would apple object you?

You can surely share the image. As you mentioned you have the image you just need to use default sharing sheet. here's the code:

NSArray *activityItems = [NSArray arrayWithObjects:yourImage, nil];
UIActivityViewController *aActivityView = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
aActivityView.modalInPopover = UIModalTransitionStyleCoverVertical;
[self presentViewController:aActivityView animated:YES completion:^{

}];

This will present an UIActivityViewController's view which will have share option in it.

Hope this helps.

My gut feeling would be; why wouldn't Apple allow this?

If you have already managed to grab a UIImage representation of your MKMapView using the Apple provided MKMapSnapshotter, I would hazard a guess that Apple have given you the tools you need to do whatever you want with the image so there would be no restrictions as to what you do with it.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top