与“iPad”失去联系。恢复与“iPad”的连接并再次运行“App Name”,或者如果“App Name”仍然是>>正在运行,您可以通过选择Debug> Attach to Process> App Name附加到它。
当我将视图连续转换为base64String以及连续打开相机并拍照时,我也收到内存警告消息
我该如何解决这个问题?
以下是关注代码: -
这里我将视图转换为图像,然后转换为base64字符串
//此字符串发送到后端
NSString *cardViewString = [UIImage encodeToBase64String:[UIImage imageWithView:cardView] ];
用于将View转换为base64字符串的方法
+(NSString *)encodeToBase64String:(UIImage *)image {
return [UIImagePNGRepresentation(image) base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn];
}
+(UIImage *)imageWithView:(UIView *)view{
// Get a UIImage from the UIView ...
UIGraphicsBeginImageContextWithOptions(view .bounds.size, NO, 0);
if ([view respondsToSelector:@selector(drawViewHierarchyInRect:afterScreenUpdates:)])
[view drawViewHierarchyInRect:view .bounds afterScreenUpdates:YES]; // if we have efficient iOS 7 method, use it ...
else
[view.layer renderInContext:UIGraphicsGetCurrentContext()]; // ... otherwise, fall back to tried and true methods
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}