Iphone 在NSURL请求时,我正在获取EXC\u BAD\u访问权限

Iphone 在NSURL请求时,我正在获取EXC\u BAD\u访问权限,iphone,objective-c,nsurlconnection,nsurlrequest,Iphone,Objective C,Nsurlconnection,Nsurlrequest,在NSURL请求时,我正在获取EXC\u BAD\u访问权限。 我通过AppDelegate_iPhone的currentBookPressed提供从服务器到webview的pdf url。 请告诉我问题出在哪里。。。 代码:- @class AppDelegate\u iPhone; @接口PdfShowViewController:UIViewController{ UIWebView*pdfWebview; AppDelegate_iPhone*AppDelegate; NSMutable

在NSURL请求时,我正在获取EXC\u BAD\u访问权限。 我通过AppDelegate_iPhone的currentBookPressed提供从服务器到webview的pdf url。 请告诉我问题出在哪里。。。 代码:-

@class AppDelegate\u iPhone;
@接口PdfShowViewController:UIViewController{
UIWebView*pdfWebview;
AppDelegate_iPhone*AppDelegate;
NSMutableData*接收数据;
UIActivityIndicatorView*myIndicator;
IBUIProgressView*进度;
NSURLRequest*下载请求;
NSURLConnection*下载连接;
久别重逢;
长期望字节;
}
@属性(非原子,保留)UIWebView*pdfWebview;
@属性(非原子,保留)UIActivityIndicatorView*myIndicator;
@属性(非原子,保留)IBUIProgressView*进度;
@属性(非原子,保留)NSM可变数据*接收数据;
@属性(非原子、只读、保留)NSURLRequest*DownloadRequest;
@属性(非原子、只读、保留)NSURLConnection*DownloadConnection;
-(IBAction)背越式;
@结束
#导入“PdfShowViewController.h”
#导入“AppDelegate_iPhone.h”
@PdfShowViewController的实现
@综合pdfWebview、myIndicator、progress、receivedData、DownloadRequest、DownloadConnection;
-(void)连接:(NSURLConnection*)连接didReceiveData:(NSData*)数据{
[接收数据附录数据:数据];
无符号char byteBuffer[[receivedData length]];
[receivedData getBytes:byteBuffer];
NSLog(@“数据===%ld”,接收数据);
NSInteger receivedLen=[数据长度];
bytesReceived=(bytesReceived+receivedLen);
NSLog(@“已接收字节==%f”,字节已接收);
if(预期字节数!=nsurresponseunknownlength)
{
NSLog(@“如果中的预期字节==%f”,则为预期字节);
NSLog(@“接收到的字节数在if=%f”,字节数已接收);
浮点值=((浮点)(字节接收*100/expectedBytes))/100;
NSLog(@“值==%f”,值);
进步。进步=价值;
}
}
-(无效)连接:(NSURLConnection*)连接失败错误:(NSError*)错误{
//[连接释放];
}
-(void)连接:(NSURLConnection*)连接DidReceiverResponse:(NSURResponse*)响应{
expectedBytes=[response expectedContentLength];
NSLog(@“%f”,预期字节);
}
-(无效)连接IDFinishLoading:(NSURLConnection*)连接{
[myIndicator停止设置动画];
[myIndicator removeFromSuperview];
pdfWebview=[[UIWebView alloc]initWithFrame:CGRectMake(0,40,320,420)];
[pdfWebview setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
[pdfWebview setScalesPageToFit:是];
[pdfWebview setAutoResizesSubView:是];
[pdfWebview loadRequest:DownloadRequest];
[self.view addSubview:pdfWebview];
//[连接释放];
}
//实现viewDidLoad以在加载视图(通常从nib)后执行附加设置。
-(无效)viewDidLoad{
[超级视图下载];
appDelegate=(appDelegate_iPhone*)[[UIApplication sharedApplication]delegate];
myIndicator=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
myIndicator.center=self.view.center;
myIndicator.hidesWhenStopped=否;
[self.view addSubview:myIndicator];
[myIndicator startAnimating];
//receivedData=[[NSMutableData alloc]initWithLength:0];
NSLog(@“%@”,appDelegate.currentBookPressed);
NSString*urlString=[appDelegate.currentBookPressed stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
NSLog(@“%@”,urlString);
NSURL*targetURL=[NSURL URLWithString:urlString];
NSLog(@“%@”,targetURL);
//接受来了
DownloadRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:targetURL]缓存策略:NSURLRequestReturnCacheDataElseLoad timeoutInterval:120.0];
DownloadConnection=[[NSURLConnection alloc]initWithRequest:DownloadRequest委托:self];
if(下载连接){
receivedData=[[NSMutableData]initWithLength:0]保留];
}
}
//替代以允许默认纵向方向以外的方向。
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{
返回YES;
}
-(无效)未收到记忆警告{
[超级记忆警告];
}
-(无效)视图卸载{
[超级视频下载];
}
-(iAction)onTapBack
{
[自我解散Modalviewcontrolleranimated:是];
}
-(无效)解除锁定{
[super dealoc];
[pdfWebview发布];
[接收数据发布];
}
@结束

您应该更换线路

DownloadRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:targetURL] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:120.0];
用线

DownloadRequest = [NSURLRequest requestWithURL:targetURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:120.0];
这是因为第一个参数中的方法
requestWithURL:cachePolicy:timeoutInterval:
正在等待
NSURL
类的对象。在
targetUrl
中,您正好有一个


此外,在方法
[nsurlwithstring:targetURL]
中(如果需要),您应该将
NSString
作为第一个参数传递,但您正在传递
NSURL

您应该更换线路

DownloadRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:targetURL] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:120.0];
用线

DownloadRequest = [NSURLRequest requestWithURL:targetURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:120.0];
这是因为第一个参数中的方法
requestWithURL:cachePolicy:timeoutInterval:
正在等待
NSURL
类的对象。在
targetUrl
中,您正好有一个


此外,在方法
[nsurlwithstring:targetURL]
中(如果需要),您应该将
NSString
作为第一个参数传递,但您正在传递
NSURL

您在这方面的问题

DownloadRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:targetURL] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:120.0];  

本例中出现的问题是因为
+(id)URLWithString:(NSString*)URLString
的参数是
NSString
,您正在传递NSURL和方法,试图通过调用
-length
来获取假定字符串的长度,该参数存在于NSString中,但不存在于NSURL中。

您在这一行中遇到的问题

DownloadRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:targetURL] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:120.0];  
本例中出现的问题是因为
+(id)URLWithString:(NSString*)URLString
的参数是
NSString
,并且您正在传递NSURL和方法,试图获取长度o