PDFViewController.m 3.73 KB
Newer Older
勾芒's avatar
勾芒 committed
1 2 3 4 5 6 7 8 9 10
//
//  PDFViewController.m
//  Lighting
//
//  Created by 曹云霄 on 16/5/17.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "PDFViewController.h"

勾芒's avatar
勾芒 committed
11
@interface PDFViewController ()<UIWebViewDelegate>
勾芒's avatar
勾芒 committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25

@property (nonatomic,strong) UIWebView *webView;

@end

@implementation PDFViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self uiConfigAction];
}

勾芒's avatar
勾芒 committed
26 27


勾芒's avatar
勾芒 committed
28
- (BOOL)prefersStatusBarHidden
勾芒's avatar
勾芒 committed
29
{
勾芒's avatar
勾芒 committed
30
    return YES;
勾芒's avatar
勾芒 committed
31 32
}

勾芒's avatar
勾芒 committed
33 34 35 36

//
//#pragma mark -UI
- (void)uiConfigAction
勾芒's avatar
勾芒 committed
37
{
勾芒's avatar
勾芒 committed
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
//    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
//    [self.view addSubview:self.webView];
//    self.webView.delegate = self;
////    NSString * strUrl = [[NSString alloc]initWithContentsOfURL:[NSURL URLWithString:_pdfURLString] encoding:NSUTF8StringEncoding error:nil];
//    
//    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_pdfURLString]];
////    NSURL *url = [NSURL URLWithString:_pdfURLString];
////    if ([url pathExtension] && ([[[url pathExtension] lowercaseString] isEqualToString:@"txt"] || [[[url pathExtension] lowercaseString] isEqualToString:@"text"]))
////    {
//////        return [self convertTxtEncoding:url];
////        NSURLRequest *request = [NSURLRequest requestWithURL:[self convertTxtEncoding:url]];
////         [self.webView loadRequest:request];
////    }
////    else
////    {
//////        return url;
////        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:_pdfURLString]];
////        [self.webView loadRequest:request];
////    }
//    [self.webView loadRequest:request];
    [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(PDFClickAction)]];
勾芒's avatar
勾芒 committed
59
}
勾芒's avatar
勾芒 committed
60 61
#pragma mark -dismiss
- (void)PDFClickAction
勾芒's avatar
勾芒 committed
62 63 64
{
    [self dismissViewControllerAnimated:YES completion:nil];
}
勾芒's avatar
勾芒 committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
//
//
//#pragma mark -加载错误
//- (void)webView:(UIWebView *)webView didFailLoadWithError:(nullable NSError *)error
//{
//    [self ErrorMBProgressView:@"加载错误"];
//    [self dismissViewControllerAnimated:YES completion:nil];
//}
//
//
//
//- (NSURL *)convertTxtEncoding:(NSURL *)fileUrl
//
//{
////    
////    if ([FileManagementAPI getFileSize:[fileUrl path]] > 1024*1024.0f)
////        
////    {
////        
////        return fileUrl;
////        
////    }
//    
//    NSString *tmpFilePath = [NSString stringWithFormat:@"%@/tmp/%@", NSHomeDirectory(), [fileUrl lastPathComponent]];
//    
//    NSLog(@"tmpFilePath=%@", tmpFilePath);
//    
//    NSURL *tmpFileUrl = [NSURL fileURLWithPath:tmpFilePath];
//    
//    NSStringEncoding encode;
//    
//    NSString *contentStr = [NSString stringWithContentsOfURL:fileUrl usedEncoding:&encode error:NULL];
勾芒's avatar
勾芒 committed
97
//    
勾芒's avatar
勾芒 committed
98 99 100
//    
//    
//    if (contentStr)
勾芒's avatar
勾芒 committed
101 102 103
//        
//    {
//        
勾芒's avatar
勾芒 committed
104 105 106 107 108
//        [contentStr writeToURL:tmpFileUrl atomically:YES encoding:NSUTF16StringEncoding error:NULL];
//        
//        
//        
//        return tmpFileUrl;
勾芒's avatar
勾芒 committed
109 110
//        
//    }
勾芒's avatar
勾芒 committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
//    
//    else
//        
//    {
//        
//        NSStringEncoding convertEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);
//        
//        contentStr = [NSString stringWithContentsOfURL:fileUrl encoding:convertEncoding error:NULL];
//        
//        
//        
//        if (contentStr)
//            
//        {
//            
//            [contentStr writeToURL:tmpFileUrl atomically:YES encoding:NSUTF16StringEncoding error:NULL];
//            
//            
//            
//            return tmpFileUrl;
//            
//        }
//        
//        else
//            
//        {
//            
//            return fileUrl;
//            
//        }
//        
//    }
//    
//}
勾芒's avatar
勾芒 committed
145

勾芒's avatar
勾芒 committed
146 147 148 149 150





勾芒's avatar
勾芒 committed
151
@end