我有一个问题MKMapSnapshotter
。我目前有两个视图,一个带有 a UIButton
,它显示 a UIActivityViewController
,一个带有 a MKMapView
,它显示当前用户位置。UIActivityViewController
用于共享用户的坐标,并从UIImage
显示MKMapView
当前位置获取。
图片是使用MKMapSnapshotter
以下代码拍摄的secondViewController.m
:
- (void)mapViewDidFinishRenderingMap:(MKMapView *)mapView fullyRendered:(BOOL)fullyRendered
{
snapshotOptions = [[MKMapSnapshotOptions alloc] init];
snapshotOptions.region = self.mapView.region;
snapshotOptions.scale = [UIScreen mainScreen].scale;
snapshotOptions.size = self.mapView.frame.size;
snapShotter = [[MKMapSnapshotter alloc] initWithOptions:snapshotOptions];
[snapShotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error)
{
snapshotImage = snapshot.image;
data = UIImagePNGRepresentation(snapshotImage);
[data writeToFile:@"SOS_Map.png" atomically:YES];
}];
}
并保存到名为: 的文件SOS_Map.png
中,如您所见。问题是,如果我尝试加载.png
文件,它不会出现在UIActivityViewController
邮件/消息应用程序中。我确信这张照片确实已经拍摄并且代码有效[即使因为我已经用 测试过它NSLogs
],但我仍然无法加载图像。
这是用于启动UIActivityViewController
、添加文本和加载的UIImage
代码firstViewController.m
- (IBAction)shareCoordinates:(id)sender
{
myBundle = [NSBundle mainBundle];
pathToImage = [myBundle pathForResource:@"SOS_Map" ofType:@"png"];
itemsToShare = [NSMutableArray new];
[itemsToShare addObject:[NSString stringWithFormat:@"text]]; //Coordinates
[itemsToShare addObject:[UIImage imageNamed:@"SOS_Map.png"]]; //Picture
itemsToShareLoaded = [NSArray arrayWithArray:itemsToShare];
_activityView = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare
applicationActivities:nil];
[self presentViewController:_activityView animated:YES completion:nil];
}
可能是文件目录问题?我不知道,你能帮我解决这个问题吗?