0

だから私はphp(IPボード)で構築されたウェブサイトを持っています.zip、debなどのファイル拡張子を検出できるダウンロードマネージャーをiOSアプリに持っています.しかし、私はそれにURLを認識させる方法を見つけることができませんボードは、ファイルを添付するために使用します。

私が今使用している私のコード:

//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;
}

現在、サイトは次のようなリンクを提供する添付ファイルをアップロードしています。

http://mysite.com/index.php?app=core&module=attach§ion=attach&attach_id=38354

これを達成する最良の方法は何ですか?

ご協力ありがとうございました。

更新 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&section=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:

ここで何か他のことを試してみましたが、まだView Controllerをプッシュしていません。

NSURL *url = [request URL];
NSString *id = @"12212323";
NSString *fullURL = [[url pathExtension] initWithFormat:@"www.mysite.com/index.php?app=core&module=attach&section=attach&attach_id=%@", id];

次のログをスローします。

* WebKit は webView:decidePolicyForNavigationAction:request:frame:decisionListener: delegate: でキャッチされていない例外を破棄しました: *初期化メソッド -initWithFormat:locale:arguments: クラス NSPathStore2 の抽象オブジェクトに送信できません: 具体的なインスタンスを作成してください!

4

1 に答える 1