Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios -writeToURL未覆盖上一次写入_Ios_Nsfilemanager - Fatal编程技术网

Ios -writeToURL未覆盖上一次写入

Ios -writeToURL未覆盖上一次写入,ios,nsfilemanager,Ios,Nsfilemanager,更新#1:忘了提到这是在iPad应用程序上运行的 这是我修改过的代码(仍然不起作用,但去掉了不必要的代码): 当我在XCode调试器中查看custImage时,我看到一个与前一个图像不同的图像,这是正确的。但是,当它有时间在fileURL上显示图像时,它与custImage完全不同,并且是第一次显示的同一图像 更新#2:我发现fileURL具有正确的映像,但第二次没有写入设备(第一个映像没有被替换)。 更新#3:这是显示在UIWebView弹出窗口中的htmlString的内容: <htm

更新#1:忘了提到这是在iPad应用程序上运行的

这是我修改过的代码(仍然不起作用,但去掉了不必要的代码):

当我在XCode调试器中查看custImage时,我看到一个与前一个图像不同的图像,这是正确的。但是,当它有时间在fileURL上显示图像时,它与custImage完全不同,并且是第一次显示的同一图像

更新#2:我发现fileURL具有正确的映像,但第二次没有写入设备(第一个映像没有被替换)。

更新#3:这是显示在UIWebView弹出窗口中的htmlString的内容:

<html><head><style type="text/css"> body {font-family: "Verdana"; font-size: 12;} </style></head><body>  
<h2>Rolf Marsh</h2><p>phone: 213-555-1234<p>services: Art, Decals<p><img src="file:///private/var/mobile/Applications/FEE7159E-1FF8-4B94-A446-2A4C72E0AD41/tmp/custImage.png"/></body></html>
正文{字体系列:“Verdana”;字体大小:12;}
Rolf Marsh电话:213-555-1234服务:艺术、贴花

有没有关于如何解决这个问题的建议?

据我所知,您从未将数据写入磁盘

只有在已注释掉的部分中,您才尝试删除

将其写在:

NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"custImage"] URLByAppendingPathExtension:@"png"];    
//write 
NSError*writeError = nil;
[client.aClientImage writeToURL:fileURL options:0 error:&writeError];
NSAssert(writeError==nil, writeError);

//read / use in the html or so 
...


别忘了重新加载web视图或用于显示html的任何内容

我想出来了。。。对于其他有相同问题的人,下面是有效的代码。请注意,我没有将其保存到临时文件中,因为我在核心数据实体中已经有了该图像。代码如下:

-(void) showExistingAppointmentDetails: (AppointmentInfo *) apptSelected  {

//  make rectangle to attach popover
CGRect rectangle = CGRectMake( [apptSelected.aPosX floatValue], [apptSelected.aPosY floatValue],
                              [apptSelected.aPosW floatValue], [apptSelected.aPosH floatValue]);

//  see if this is for staff; if so, don't display anything
if([apptSelected.aApptKey isEqual: @"Staff"])
    return;

NSPredicate *predicate =  ([NSPredicate predicateWithFormat: @"aClientKey == %@", apptSelected.aApptKey ]);  //  was aApptKey
ClientInfo *client = [ClientInfo MR_findFirstWithPredicate:predicate inContext:localContext];

UIImage *image = [UIImage imageWithData:client.aClientImage];  //  image is good  <---------

//  write appointment info into html string
NSString *htmlString;
if(client.aClientEMail.length > 0)  {
    htmlString = [NSString stringWithFormat:NSLocalizedString(@"HTML_STRING1",nil),
                  client.aClientFirstName,
                  client.aClientLastName,
                  client.aClientEMail.length == 0? @"": client.aClientEMail,
                  client.aClientPrimaryPhone,
                  apptSelected.aServices,
                  [self htmlForPNGImage:image]];
}
else  {
    htmlString = [NSString stringWithFormat:NSLocalizedString(@"HTML_STRING2",nil),
                  client.aClientFirstName,
                  client.aClientLastName,
                  client.aClientPrimaryPhone,
                  apptSelected.aServices,
                  [self htmlForPNGImage:image]];

}

UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 300)];
popoverView.backgroundColor = [UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0];  //  frame color?
popoverContent.view = popoverView;

//resize the popover view shown in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(250, 300);

//  add the UIWebView for RichText
UIWebView *webView = [[UIWebView alloc] initWithFrame:popoverView.frame];
webView.backgroundColor = [UIColor whiteColor];  //  change background color here

//  add the webView to the popover
[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:nil]];
[popoverView addSubview:webView];

//  if previous popoverController is still visible... dismiss it
if ([popoverController isPopoverVisible]) {
    [popoverController dismissPopoverAnimated:YES];
}

//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:rectangle inView:self
                 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}


- (NSString *) htmlForPNGImage:(UIImage *) image {

NSData *imageData = UIImagePNGRepresentation(image);
NSString *imageSource = [NSString stringWithFormat:@"data:image/png;base64,%@",[imageData base64Encoding]];
return [NSString stringWithFormat:@"%@", imageSource];

}
-(无效)显示现有任命详细信息:(任命信息*)已选择应用程序{
//制作矩形以附加popover
CGRect矩形=CGRectMake([apptSelected.aPosX floatValue],[apptSelected.aPosY floatValue],
[apptSelected.aPosW floatValue],[apptSelected.aPosH floatValue];
//看看这是否是给员工的;如果是,不要显示任何内容
如果([apptSelected.aApptKey isEqual:@“Staff”])
返回;
NSPredicate*谓词=([NSPredicate predicateWithFormat:@“aClientKey==%@”,apptSelected.aApptKey]);//是aApptKey
ClientInfo*client=[ClientInfo MR_findFirstWithPredicate:predicate inContext:localContext];
UIImage*image=[UIImage imageWithData:client.aClientImage];//图像良好(0){
htmlString=[NSString stringWithFormat:NSLocalizedString(@“HTML_STRING1”,nil),
client.aClientFirstName,
client.aClientLastName,
client.aClientEMail.length==0?@“”:client.aClientEMail,
client.aClientPrimaryPhone,
apptSelected.a服务,
[自HTMLFormginImage:image];
}
否则{
htmlString=[NSString stringWithFormat:NSLocalizedString(@“HTML_STRING2”,nil),
client.aClientFirstName,
client.aClientLastName,
client.aClientPrimaryPhone,
apptSelected.a服务,
[自HTMLFormginImage:image];
}
UIViewController*popoverContent=[[UIViewController alloc]init];
UIView*popoverView=[[UIView alloc]initWithFrame:CGRectMake(0,0,250,300)];
popoverView.backgroundColor=[UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0];//帧颜色?
popoverContent.view=popoverView;
//将当前视图中显示的popover视图调整为视图的大小
popoverContent.contentSizeForViewInPopover=CGSizeMake(250300);
//为RichText添加UIWebView
UIWebView*webView=[[UIWebView alloc]initWithFrame:popoverView.frame];
webView.backgroundColor=[UIColor whiteColor];//在此处更改背景色
//将webView添加到弹出窗口
[webView加载htmlString:htmlString baseURL:[NSURL URLWithString:nil]];
[popoverView addSubview:webView];
//如果以前的popoverController仍然可见…请将其关闭
如果([popoverController ispoverVisible]){
[popoverController解除PopOveranimated:是];
}
//创建一个popover控制器
popoverController=[[UIPopoverController alloc]initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:矩形查看:自
许可证箭头方向:UIPopOver箭头方向任何动画:是];
}
-(NSString*)HTMLFormginImage:(UIImage*)图像{
NSData*imageData=UIImagePNGRepresentation(图像);
NSString*imageSource=[NSString stringWithFormat:@“数据:图像/png;base64,%@,[imageData base64编码]];
返回[NSString stringWithFormat:@“%@”,imageSource];
}

我认为你很接近,但这并没有解决问题。。。我知道**custImage**是正确的,因为我可以在调试器中看到它。让我更新原始问题中的代码(我发现很多代码什么都没做)确保你可以在diskDaij Djan上的finder中看到custImage:这是在iPad应用程序上运行的。。。无查找程序:-{然后查看它是否在磁盘上被更改。至少在iOS模拟器中
-(void) showExistingAppointmentDetails: (AppointmentInfo *) apptSelected  {

//  make rectangle to attach popover
CGRect rectangle = CGRectMake( [apptSelected.aPosX floatValue], [apptSelected.aPosY floatValue],
                              [apptSelected.aPosW floatValue], [apptSelected.aPosH floatValue]);

//  see if this is for staff; if so, don't display anything
if([apptSelected.aApptKey isEqual: @"Staff"])
    return;

NSPredicate *predicate =  ([NSPredicate predicateWithFormat: @"aClientKey == %@", apptSelected.aApptKey ]);  //  was aApptKey
ClientInfo *client = [ClientInfo MR_findFirstWithPredicate:predicate inContext:localContext];

UIImage *image = [UIImage imageWithData:client.aClientImage];  //  image is good  <---------

//  write appointment info into html string
NSString *htmlString;
if(client.aClientEMail.length > 0)  {
    htmlString = [NSString stringWithFormat:NSLocalizedString(@"HTML_STRING1",nil),
                  client.aClientFirstName,
                  client.aClientLastName,
                  client.aClientEMail.length == 0? @"": client.aClientEMail,
                  client.aClientPrimaryPhone,
                  apptSelected.aServices,
                  [self htmlForPNGImage:image]];
}
else  {
    htmlString = [NSString stringWithFormat:NSLocalizedString(@"HTML_STRING2",nil),
                  client.aClientFirstName,
                  client.aClientLastName,
                  client.aClientPrimaryPhone,
                  apptSelected.aServices,
                  [self htmlForPNGImage:image]];

}

UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 250, 300)];
popoverView.backgroundColor = [UIColor colorWithWhite:(CGFloat)1.0 alpha:(CGFloat)1.0];  //  frame color?
popoverContent.view = popoverView;

//resize the popover view shown in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(250, 300);

//  add the UIWebView for RichText
UIWebView *webView = [[UIWebView alloc] initWithFrame:popoverView.frame];
webView.backgroundColor = [UIColor whiteColor];  //  change background color here

//  add the webView to the popover
[webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:nil]];
[popoverView addSubview:webView];

//  if previous popoverController is still visible... dismiss it
if ([popoverController isPopoverVisible]) {
    [popoverController dismissPopoverAnimated:YES];
}

//create a popover controller
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:rectangle inView:self
                 permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}


- (NSString *) htmlForPNGImage:(UIImage *) image {

NSData *imageData = UIImagePNGRepresentation(image);
NSString *imageSource = [NSString stringWithFormat:@"data:image/png;base64,%@",[imageData base64Encoding]];
return [NSString stringWithFormat:@"%@", imageSource];

}