即将面临过去4天的问题,即我必须在视图控制器上打开相机,上面有地图,并且必须将点击的图像(原始大小)保存在图库中,这样我的应用程序开始接收内存警告和一段时间后才崩溃..
我认为问题在于每次取消图像拾取器时我的地图都会开始渲染。
同样崩溃的是特定的ios和设备,即ios 8.1.3 + iphone 4s。
任何建议都表示赞赏。
请帮忙。
答案 0 :(得分:0)
在一个忙碌的周末之后,我找到了解决方案,虽然它是一个补丁但对我有用。所以我做了什么我只是阻止主线程直到图像选择器控制器被解雇。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
__weak typeof(picker) wSelf = picker;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[wSelf dismissViewControllerAnimated:YES completion:^{
@try {
[self saveImage:info];
}
@catch (NSException *exception) {
NSLog(@"Exception:%@",exception);
}
@finally {
}
}];});}
-(void)saveImage:(NSDictionary *)info{
[KAppdelegate ShowLoader];
UIImage *image=(UIImage *)[info objectForKey:@"UIImagePickerControllerOriginalImage"];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
dispatch_queue_t queue = dispatch_queue_create("com.myApp.saveToCameraRoll", NULL);
dispatch_async(queue, ^{
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[library writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
// handle the error
}
else {
dispatch_async(dispatch_get_main_queue(), ^{
// perhaps indicate to the user that save has finished
});
}
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
});}