Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. fbVC = [[FileBrowserTableViewController alloc] init];
  2. fbVC.delegate = self;
  3. fbVC.path = @"/";
  4. navigationController = [[UINavigationController alloc] initWithRootViewController:fbVC];
  5. navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
  6.  
  7. - (void)fileBrowser:(FileBrowserTableViewController *)fileBrowser didFinishWithFileURL:(NSURL *)fileURLPath {
  8. NSString *extString = [fileURLPath absoluteString];
  9. NSString *ext = [[extString pathExtension] lowercaseString];
  10. NSString* theFileName = [[extString lastPathComponent] stringByDeletingPathExtension];
  11.  
  12. CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)fileURLPath.pathExtension, NULL);
  13. CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
  14. NSString *MIMETypeString = (__bridge NSString*)MIMEType;
  15.  
  16. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"TGEnhancer" message:[NSString stringWithFormat:@"---URL : %@ --FileName : %@ --ext %@: mimetype : %@", fileURLPath, theFileName, fileURLPath.pathExtension, MIMETypeString] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
  17. [alertView show];
  18. [self.companion controllerWantsToSendDocumentWithTempFileUrl:fileURLPath fileName:[NSString stringWithFormat:@"[TGEnhancer]%@.%@",theFileName, fileURLPath.pathExtension] mimeType:MIMETypeString];
  19. // [fileBrowser.navigationController popViewControllerAnimated:YES];
  20. [fileBrowser.navigationController dismissViewControllerAnimated:YES completion:^{
  21. NSLog(@"File Browser - Finished");
  22. }];
  23. }
  24.  
  25. @protocol FileBrowserTableViewControllerDelegate;
  26.  
  27. @interface FileBrowserTableViewController : UITableViewController
  28. {
  29. NSString *path;
  30. NSMutableArray *files;
  31. }
  32.  
  33. @property (nonatomic,retain) NSString *path;
  34. @property (nonatomic,retain) NSMutableArray *files;
  35. @property (nonatomic, strong) id<FileBrowserTableViewControllerDelegate> delegate;
  36.  
  37. @end
  38.  
  39. @protocol FileBrowserTableViewControllerDelegate <NSObject>
  40. @optional
  41. - (void)fileBrowser:(FileBrowserTableViewController *)fileBrowser didFinishWithFileURL:(NSURL *)fileURLPath;
  42. - (void)fileBrowserDidCancel:(FileBrowserTableViewController *)fileBrowser;
  43.  
  44. @end
  45.  
  46. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  47. File *aFile = [files objectAtIndex:indexPath.row];
  48. if(aFile.isDirectory)
  49. {
  50. FileBrowserTableViewController *anotherViewController = [[FileBrowserTableViewController alloc] init];
  51. anotherViewController.path = [path stringByAppendingPathComponent:aFile.name];
  52. [self.navigationController pushViewController:anotherViewController animated:YES];
  53. } else {
  54. [self doOpenFileAtIndexPath:indexPath];
  55. }
  56. }
  57.  
  58. - (void)doOpenFileAtIndexPath:(NSIndexPath*)indexPath {
  59. // File *aFile = [files objectAtIndex:indexPath.row];
  60. [self openFileAtIndexPath:indexPath];
  61. }
  62.  
  63. - (void)openFileAtIndexPath:(NSIndexPath*)indexPath
  64. {
  65. File *aFile = [files objectAtIndex:indexPath.row];
  66. NSString *extension = [[aFile.name pathExtension] lowercaseString];
  67. NSString *fullpath = [path stringByAppendingPathComponent:aFile.name];
  68. NSURL *filePathUrl = [NSURL fileURLWithPath:fullpath];
  69. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"Type Existe"
  70. message:[NSString stringWithFormat:@"--Name : %@ Fullpath : %@", aFile.name, fullpath]
  71. delegate:nil
  72. cancelButtonTitle:@"OK"
  73. otherButtonTitles:nil];
  74. [alertView show];
  75. [self.delegate fileBrowser:self didFinishWithFileURL:filePathUrl];
  76. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement