瀏覽代碼

URL handling: add error handling and behave correctly when saving files

Felix Paul Kühne 12 年之前
父節點
當前提交
f73746474a
共有 1 個文件被更改,包括 6 次插入5 次删除
  1. 6 5
      AspenProject/VLCAppDelegate.m

+ 6 - 5
AspenProject/VLCAppDelegate.m

@@ -43,7 +43,7 @@
     if (_playlistViewController && url != nil) {
         APLog(@"%@ requested %@ to be opened", sourceApplication, url);
 
-        if (url.isFileURL || [url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"]) {
+        if (url.isFileURL) {
             UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"SAVE_FILE", @"") message:[NSString stringWithFormat:NSLocalizedString(@"SAVE_FILE_LONG", @""), url.lastPathComponent] delegate:self cancelButtonTitle:NSLocalizedString(@"BUTTON_CANCEL", @"") otherButtonTitles:NSLocalizedString(@"BUTTON_SAVE", @""), nil];
             _tempURL = url;
             [alert show];
@@ -59,14 +59,15 @@
     if (buttonIndex == 1) {
         NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
         NSString *directoryPath = searchPaths[0];
-        NSURL *destinationURL = [NSURL URLWithString:[NSString stringWithFormat:@"file://%@/%@", directoryPath, _tempURL.lastPathComponent]];
+        NSURL *destinationURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@", directoryPath, _tempURL.lastPathComponent]];
         NSError *theError;
         [[NSFileManager defaultManager] copyItemAtURL:_tempURL toURL:destinationURL error:&theError];
+        if (theError.code != noErr)
+            APLog(@"saving the file failed (%i): %@", theError.code, theError.localizedDescription);
 
         [self updateMediaList];
-    }
-
-    [_playlistViewController openMovieFromURL:_tempURL];
+    } else
+        [_playlistViewController openMovieFromURL:_tempURL];
 }
 
 - (void)applicationWillResignActive:(UIApplication *)application