|
@@ -14,8 +14,12 @@
|
|
|
#define LABEL_MARGIN 5
|
|
#define LABEL_MARGIN 5
|
|
|
#import "TabBarController.h"
|
|
#import "TabBarController.h"
|
|
|
#import "DetailCellTracking.h"
|
|
#import "DetailCellTracking.h"
|
|
|
|
|
+#import <QuickLook/QuickLook.h>
|
|
|
|
|
|
|
|
-@interface DetailPageViewController ()
|
|
|
|
|
|
|
+@interface DetailPageViewController () <QLPreviewControllerDataSource,QLPreviewControllerDelegate>
|
|
|
|
|
+
|
|
|
|
|
+@property (nonatomic,strong) QLPreviewController *quickLook;
|
|
|
|
|
+@property (nonatomic,copy) NSString *documentPath;
|
|
|
|
|
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
@@ -73,8 +77,41 @@
|
|
|
// self.view.backgroundColor= [UIColor whiteColor];
|
|
// self.view.backgroundColor= [UIColor whiteColor];
|
|
|
[self loadpage];
|
|
[self loadpage];
|
|
|
// Do any additional setup after loading the view.
|
|
// Do any additional setup after loading the view.
|
|
|
|
|
+
|
|
|
|
|
+ UIBarButtonItem *saveBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_save"] style:UIBarButtonItemStylePlain target:self action:@selector(saveDocumentClick:)];
|
|
|
|
|
+ self.quickLook.navigationItem.rightBarButtonItem = saveBtn;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)saveDocumentClick:(id)sender {
|
|
|
|
|
+
|
|
|
|
|
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
|
|
+ NSString *path = [paths objectAtIndex:0];
|
|
|
|
|
+ NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]];
|
|
|
|
|
+
|
|
|
|
|
+ NSError *err;
|
|
|
|
|
+
|
|
|
|
|
+ if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
|
|
|
|
|
+ [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
|
|
|
|
|
+ }
|
|
|
|
|
+ [[NSFileManager defaultManager] moveItemAtPath:self.documentPath toPath:filePath error:&err];
|
|
|
|
|
+
|
|
|
|
|
+ UIAlertController *alertVC;
|
|
|
|
|
+ UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
|
|
+
|
|
|
|
|
+ }];
|
|
|
|
|
+ if (err) {
|
|
|
|
|
+ alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"save document failed:\n%@",err.localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alertVC = [UIAlertController alertControllerWithTitle:nil message:@"save document success" preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
+ }
|
|
|
|
|
+ [alertVC addAction:action];
|
|
|
|
|
+
|
|
|
|
|
+ [self presentViewController:alertVC animated:YES completion:nil];
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
- (void)didReceiveMemoryWarning
|
|
- (void)didReceiveMemoryWarning
|
|
|
{
|
|
{
|
|
|
[super didReceiveMemoryWarning];
|
|
[super didReceiveMemoryWarning];
|
|
@@ -194,7 +231,114 @@
|
|
|
// return UIInterfaceOrientationLandscapeRight;
|
|
// return UIInterfaceOrientationLandscapeRight;
|
|
|
//}
|
|
//}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
|
+- (void)showDocument:(NSString *)url {
|
|
|
|
|
+
|
|
|
|
|
+ __weak typeof(self) weakSelf = self;
|
|
|
|
|
+
|
|
|
|
|
+ // show alert
|
|
|
|
|
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle: nil
|
|
|
|
|
+ message: @"loading..."
|
|
|
|
|
+ preferredStyle: UIAlertControllerStyleAlert];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ UIViewController *customVC = [[UIViewController alloc] init];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
|
|
|
|
+ spinner.color = [UIColor darkGrayColor];
|
|
|
|
|
+ [spinner startAnimating];
|
|
|
|
|
+ [customVC.view addSubview:spinner];
|
|
|
|
|
+
|
|
|
|
|
+ [customVC.view addConstraint:[NSLayoutConstraint
|
|
|
|
|
+ constraintWithItem: spinner
|
|
|
|
|
+ attribute:NSLayoutAttributeCenterX
|
|
|
|
|
+ relatedBy:NSLayoutRelationEqual
|
|
|
|
|
+ toItem:customVC.view
|
|
|
|
|
+ attribute:NSLayoutAttributeCenterX
|
|
|
|
|
+ multiplier:1.0f
|
|
|
|
|
+ constant:0.0f]];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ [customVC.view addConstraint:[NSLayoutConstraint
|
|
|
|
|
+ constraintWithItem: spinner
|
|
|
|
|
+ attribute:NSLayoutAttributeCenterY
|
|
|
|
|
+ relatedBy:NSLayoutRelationEqual
|
|
|
|
|
+ toItem:customVC.view
|
|
|
|
|
+ attribute:NSLayoutAttributeCenterY
|
|
|
|
|
+ multiplier:1.0f
|
|
|
|
|
+ constant:0.0f]];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ [alertController setValue:customVC forKey:@"contentViewController"];
|
|
|
|
|
+
|
|
|
|
|
+ [self presentViewController: alertController animated: YES completion: nil];
|
|
|
|
|
+
|
|
|
|
|
+ // download
|
|
|
|
|
+ dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
|
|
+
|
|
|
|
|
+ // NSArray *paths = NSSearchPathForDirectoriesInDomains(nstem, NSUserDomainMask, YES);
|
|
|
|
|
+ // NSString *documents = [paths objectAtIndex:0];
|
|
|
|
|
+ // NSString *cacheDir = [documents stringByAppendingPathComponent:[module_name stringByAppendingString:@"_download"]];
|
|
|
|
|
+
|
|
|
|
|
+ NSString *cacheDir = NSTemporaryDirectory();
|
|
|
|
|
+
|
|
|
|
|
+ if (![[NSFileManager defaultManager] fileExistsAtPath:cacheDir]) {
|
|
|
|
|
+ [[NSFileManager defaultManager] createDirectoryAtPath:cacheDir withIntermediateDirectories:NO attributes:nil error:nil];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // NSString *path = [cacheDir stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ [RANetwork download_file:nil url:url toCachePath:cacheDir progressHandler:^(NSURLSessionTask *task, double progress) {
|
|
|
|
|
+
|
|
|
|
|
+ DebugLog(@"download progress %f",progress);
|
|
|
|
|
+ } completionHandler:^(NSMutableDictionary *result) {
|
|
|
|
|
+
|
|
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
+
|
|
|
|
|
+ weakSelf.documentPath = nil;
|
|
|
|
|
+ [alertController dismissViewControllerAnimated:YES completion:^{
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if ([[result objectForKey:@"result"] intValue] == RESULT_TRUE) {
|
|
|
|
|
+
|
|
|
|
|
+ NSString *cachePath = [result objectForKey:@"path"];
|
|
|
|
|
+ weakSelf.documentPath = cachePath;
|
|
|
|
|
+
|
|
|
|
|
+ if (cachePath) { // push 必须在completion中
|
|
|
|
|
+ [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:YES];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+
|
|
|
|
|
+ NSString *msg = [result objectForKey:@"msg"];
|
|
|
|
|
+
|
|
|
|
|
+ UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning"
|
|
|
|
|
+ message: msg
|
|
|
|
|
+ preferredStyle: UIAlertControllerStyleAlert];
|
|
|
|
|
+ UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
|
|
|
|
|
+
|
|
|
|
|
+ }];
|
|
|
|
|
+ [alertVC addAction:action];
|
|
|
|
|
+ [weakSelf presentViewController:alertVC animated:YES completion:nil];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ DebugLog(@"download result %@",result);
|
|
|
|
|
+
|
|
|
|
|
+ }];
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
#pragma mark - web view delegate
|
|
#pragma mark - web view delegate
|
|
|
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
|
|
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
|
|
@@ -206,13 +350,16 @@
|
|
|
NSString* str = request.URL.absoluteString;
|
|
NSString* str = request.URL.absoluteString;
|
|
|
if([str isEqualToString:@"about:blank"])
|
|
if([str isEqualToString:@"about:blank"])
|
|
|
return true;
|
|
return true;
|
|
|
- WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
|
|
|
|
|
- ViewController.url = str;
|
|
|
|
|
- // ViewController. = self.function_name;
|
|
|
|
|
- // ViewController.behavior =BEHAVIOR_SEARCH;
|
|
|
|
|
|
|
+// WebViewController *ViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"WebViewController"];
|
|
|
|
|
+// ViewController.url = str;
|
|
|
|
|
+// // ViewController. = self.function_name;
|
|
|
|
|
+// // ViewController.behavior =BEHAVIOR_SEARCH;
|
|
|
|
|
+//
|
|
|
|
|
+// [self.navigationController pushViewController:ViewController animated:YES];
|
|
|
|
|
+// DebugLog(@"shouldStartLoadWithRequest");
|
|
|
|
|
+
|
|
|
|
|
+ [self showDocument:request.URL.absoluteString];
|
|
|
|
|
|
|
|
- [self.navigationController pushViewController:ViewController animated:YES];
|
|
|
|
|
- DebugLog(@"shouldStartLoadWithRequest");
|
|
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- (void)webViewDidFinishLoad:(UIWebView *)webView
|
|
- (void)webViewDidFinishLoad:(UIWebView *)webView
|
|
@@ -730,4 +877,45 @@
|
|
|
return nil;
|
|
return nil;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#pragma mark - Quick Look
|
|
|
|
|
+
|
|
|
|
|
+- (QLPreviewController *)quickLook {
|
|
|
|
|
+ if (!_quickLook)
|
|
|
|
|
+ {
|
|
|
|
|
+ _quickLook = [[QLPreviewController alloc] init];
|
|
|
|
|
+ _quickLook.delegate = self;
|
|
|
|
|
+ _quickLook.dataSource = self;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ [_quickLook reloadData];
|
|
|
|
|
+ }
|
|
|
|
|
+ return _quickLook;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#pragma mark - QuickLook Data Source
|
|
|
|
|
+
|
|
|
|
|
+- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (id <QLPreviewItem>) previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
|
|
|
|
|
+
|
|
|
|
|
+ return [NSURL fileURLWithPath:self.documentPath];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+#pragma mark - QuickLook Delegate
|
|
|
|
|
+
|
|
|
|
|
+- (void) previewControllerDidDismiss:(QLPreviewController *)controller {
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 文件内部链接点击不进行外部跳转
|
|
|
|
|
+ */
|
|
|
|
|
+- (BOOL) previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id<QLPreviewItem>)item {
|
|
|
|
|
+ return NO;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@end
|
|
@end
|