从php网站解码附件url
因此,我有一个内置php(IP板)的网站,我的ios应用程序中有一个下载管理器,可以检测zip、deb等文件扩展名。但是我找不到方法让它识别板用于附加文件的url 我现在使用的代码:从php网站解码附件url,php,ios,webview,download,Php,Ios,Webview,Download,因此,我有一个内置php(IP板)的网站,我的ios应用程序中有一个下载管理器,可以检测zip、deb等文件扩展名。但是我找不到方法让它识别板用于附加文件的url 我现在使用的代码: //Download manager - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationT
//Download manager
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if(navigationType == UIWebViewNavigationTypeLinkClicked) {
NSURL *theRessourcesURL = [request URL];
NSString *fileExtension = [theRessourcesURL pathExtension];
NSLog(@"fileExtension is: %@", fileExtension);
if ([fileExtension hasSuffix:@"zip"] || [fileExtension hasSuffix:@"deb"] || [fileExtension hasSuffix:@"rar"] || [fileExtension hasSuffix:@"mp3"] || [fileExtension hasSuffix:@"pdf"] || [fileExtension hasSuffix:@"exe"] || [fileExtension hasSuffix:@"mp4"] || [fileExtension hasSuffix:@"flv"] || [fileExtension hasSuffix:@"torrent"] || [fileExtension hasSuffix:@"png"] || [fileExtension hasSuffix:@"jpg"] || [fileExtension hasSuffix:@"jpeg"]) {
NSError *error = nil; //error setting
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"downloads"];
if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath])
[[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder
HCDownloadViewController *dlvc = [[HCDownloadViewController alloc] init];
[dlvc downloadURL:theRessourcesURL userInfo:nil];
[self.navigationController setNavigationBarHidden:NO];
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0/255.0f green:0/255.0f blue:0/255.0f alpha:1];
[self.navigationController pushViewController:dlvc animated:YES];
dlvc.delegate = self;
return NO;
}
else {
}
}
return YES;
}
目前,该网站上载的附件提供如下链接:
实现这一目标的最佳方式是什么
谢谢你的帮助
更新7/17:
从我试图收集的信息来看,我试图使用下面的内容。但我似乎无法将其链接到下载管理器以启动下载视图控制器
//New method I'm trying
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *userId= [prefs stringForKey:@"userIdkey"];
NSString *urlStr = [NSString stringWithFormat:@"http://mysite.com/index.php?app=core&module=attach§ion=attach&attach_id=%@",userId];
//Need to push this view controller like the file extension code above
HCDownloadViewController *dlvc = [[HCDownloadViewController alloc] init];
[dlvc downloadURL:theRessourcesURL userInfo:nil];
更新7/18:
在这里尝试其他操作,但仍然没有推送视图控制器
NSURL *url = [request URL];
NSString *id = @"12212323";
NSString *fullURL = [[url pathExtension] initWithFormat:@"www.mysite.com/index.php?app=core&module=attach§ion=attach&attach_id=%@", id];
抛出此日志:
*WebKit丢弃了webView:DecisionPolicyFornavigationAction:request:frame:decisionListener:
委托:初始化方法
-initWithFormat:locale:arguments:无法发送到类NSPathStore2:创建具体实例的抽象对象
通过调整服务器端的一些东西解决了这个问题,然后使用这个找到了扩展
NSString *fileExtension = [[externalURL absoluteString] pathExtension];
不知道为什么在代码完全相同的情况下将其标记为“已编辑”
//My code
NSString *fileExtension = [[externalURL absoluteString] pathExtension];