所以我一直在使用sqlite3和blob,里面有pdf。我从db读取它并在加载2请求后我在模拟器中得到错误。
ViewController.m
#import
@interface ViewController : UIViewController {
NSMutableArray *lights;
}
@property (nonatomic, retain) NSMutableArray *lights;
@property (weak, nonatomic) IBOutlet UILabel *lightname;
@property (weak, nonatomic) IBOutlet UILabel *lighttype;
@property (weak, nonatomic) IBOutlet UIImageView *lightmainimage;
@property (weak, nonatomic) IBOutlet UIWebView *lightwebview;
@property (weak, nonatomic) NSURLRequest *req;
@property (weak, nonatomic) NSURL *targetURL;
@property (strong, nonatomic) NSString *appFile;
@property (weak, nonatomic) NSArray *paths;
@property (weak, nonatomic) NSString *documentsDirectory;
- (IBAction)GetLightListing:(id)sender;
@end
ViewController.m
#import "ViewController.h"
#import "LightsList.h"
#import "MyLightsList.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize lightname;
@synthesize lighttype;
@synthesize lightmainimage;
@synthesize lights;
@synthesize req;
@synthesize targetURL;
@synthesize appFile;
@synthesize paths;
@synthesize documentsDirectory;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
MyLightsList *mylights = [[MyLightsList alloc] init];
self.lights = [mylights getMyLights];
[self.lightmainimage setImage:((LightsList *) [self.lights objectAtIndex:0]).lightMainImage];
[self.lighttype setText:((LightsList *) [self.lights objectAtIndex:0]).lightType];
[self.lightname setText:((LightsList *) [self.lights objectAtIndex:0]).lightName];
self.paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
self.documentsDirectory = [self.paths objectAtIndex:0];
NSError *error;
self.documentsDirectory = [self.paths objectAtIndex:0];
self.appFile = [self.documentsDirectory stringByAppendingPathComponent:@"datasheet.pdf"];
if([((LightsList *)[self.lights objectAtIndex:0]).lightDatasheetPDF writeToFile:self.appFile options:NSDataWritingAtomic error:&error]) {
NSLog(@"file suceed!");
} else NSLog(@"file fail! %@",error);
self.targetURL = [NSURL fileURLWithPath:self.appFile];
self.req = [NSURLRequest requestWithURL:self.targetURL];
[self.lightwebview loadRequest:self.req];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)GetLightListing:(id)sender {
static NSInteger currentIndex = 0;
if(++currentIndex == [self.lights count]) {
currentIndex = 0;
} else {
LightsList *aLight = (LightsList *) [self.lights objectAtIndex:currentIndex];
[self.lightmainimage setImage:aLight.lightMainImage];
[self.lighttype setText:aLight.lightType];
[self.lightname setText:aLight.lightName];
NSError *error;
if([aLight.lightDatasheetPDF writeToFile:self.appFile options:NSDataWritingAtomic error:&error]) {
NSLog(@"file suceed!");
} else NSLog(@"file fail! %@",error);
self.targetURL = [NSURL fileURLWithPath:self.appFile];
self.req = [NSURLRequest requestWithURL:self.targetURL];
[self.lightwebview loadRequest:self.req];
}
}
@end
我确定错误被抛出[self.lightwebview loadRequest:self.req];因为如果我在它之后使用停止加载,错误不会发生或者如果我评论该行,但我真的不知道这里的问题是什么......
答案 0 :(得分:0)
存在于blob中的pdf文件存在问题,因为我在预览中打开它们并再次导出它们并将它们再次保存到数据库中它开始工作。他们显然有一些无效的数据导致了这一点。