Просмотр исходного кода

1.修改iOS Apex Mobile Detail下载文档分享。

Pen Li 8 лет назад
Родитель
Сommit
5327a093cd
1 измененных файлов с 147 добавлено и 5 удалено
  1. 147 5
      Apex Mobile/Apex Mobile/DetailPageViewController.m

+ 147 - 5
Apex Mobile/Apex Mobile/DetailPageViewController.m

@@ -17,6 +17,8 @@
 #import "DetailCellTracking.h"
 #import <QuickLook/QuickLook.h>
 #import "DetailCellKVNew.h"
+#import "MyQLPreviewController.h"
+#import "LPShareActivity.h"
 
 @interface DetailHUD : UIView
 
@@ -102,9 +104,13 @@
 
 @interface DetailPageViewController () <QLPreviewControllerDataSource,QLPreviewControllerDelegate,DetailKVCellTapDelegate>
 
-@property (nonatomic,strong) QLPreviewController *quickLook;
+@property (nonatomic,strong) MyQLPreviewController *quickLook;
 @property (nonatomic,copy) NSString *documentPath;
 
+@property (nonatomic,copy) NSString *email;
+@property (nonatomic,copy) NSString *email_subject;
+@property (nonatomic,copy) NSString *email_content;
+
 @end
 
 @implementation DetailPageViewController
@@ -162,8 +168,8 @@
     [self loadpage];
 	// 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;
+    UIBarButtonItem *previewMenuBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_menu"] style:UIBarButtonItemStylePlain target:self action:@selector(quickLookMenuClick:)];
+    self.quickLook.navigationItem.rightBarButtonItem = previewMenuBtn;
 }
 
 - (void)saveDocumentClick:(id)sender {
@@ -259,6 +265,10 @@
             {
                 self.table.hidden =false;
                 [self.table reloadData];
+                
+                self.email = [self.content.originContent objectForKey:@"email"];
+                self.email_subject = [self.content.originContent objectForKey:@"email_subject"];
+                self.email_content = [self.content.originContent objectForKey:@"email_content"];
             }
             [UIView commitAnimations];
             
@@ -1134,10 +1144,10 @@
 
 #pragma mark - Quick Look
 
-- (QLPreviewController *)quickLook {
+- (MyQLPreviewController *)quickLook {
     if (!_quickLook)
     {
-        _quickLook = [[QLPreviewController alloc] init];
+        _quickLook = [[MyQLPreviewController alloc] init];
         _quickLook.delegate = self;
         _quickLook.dataSource = self;
     }
@@ -1183,4 +1193,136 @@
     
 }
 
+#pragma mark - Quick Look Menu Action
+
+- (void)saveDocument {
+    
+    NSMutableDictionary *emailInfo = [NSMutableDictionary new];
+    if (self.email.length==0) {
+        self.email=@"";
+        
+    }
+    if (self.email_subject.length==0) {
+        self.email_subject=@"";
+        
+    }
+    if (self.email_content.length==0) {
+        self.email_content=@"";
+        
+    }
+    [emailInfo setValue:self.email forKey:@"reciptions"];
+    [emailInfo setValue:self.email_subject forKey:@"subject"];
+    [emailInfo setValue:self.email_content forKey:@"content"];
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+    NSString *path = [paths objectAtIndex:0];
+    NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]];
+    NSString *emailPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@".%@",[[self.documentPath stringByDeletingPathExtension] lastPathComponent]]];
+    
+    NSError *err;
+    
+    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
+        [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
+    }
+    [[NSFileManager defaultManager] moveItemAtPath:self.documentPath toPath:filePath error:&err];
+    
+    NSData* saved_email_data = [RAConvertor dict2data:emailInfo];
+    
+    [saved_email_data writeToFile:emailPath atomically:NO];
+    
+    
+    
+    
+    
+    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:@"Document Saved" preferredStyle:UIAlertControllerStyleAlert];
+    }
+    [alertVC addAction:action];
+    
+    [self presentViewController:alertVC animated:YES completion:nil];
+}
+
+- (void)shareDocument {
+    
+    return [self share_activity];
+}
+
+-(void) share_activity
+{
+    // 设置分享内容
+    //    NSString *text = @"分享内容";
+    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
+    NSString *path = [paths objectAtIndex:0];
+    NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]];
+    
+    // 没有保存的情况
+    if ([[NSFileManager defaultManager] fileExistsAtPath:self.documentPath]) {
+        filePath = self.documentPath;
+    }
+    
+    NSURL *url = [NSURL fileURLWithPath:filePath];
+    
+    NSArray *activityItems = @[url];
+    
+    LPShareActivity *share = [[LPShareActivity alloc] init];
+    share.to = [self.email componentsSeparatedByString:@","];//@[@"676767@qq.com"];
+    share.subject = self.email_subject;//@"test subject";
+    share.body = self.email_content;// @"body";
+    share.filePath = filePath;
+    share.handle = ^(UIViewController *vc) {
+        [self presentViewController:vc animated:YES completion:^{
+            //                [share activityDidFinish:YES];
+            // ...
+        }];
+    };
+    
+    // 服务类型控制器
+    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[share]];
+    //    _activityViewController = activityViewController;
+    //    activityViewController.excludedActivityTypes = @[UIActivityTypeMail];
+    activityViewController.modalInPopover = true;
+    [self presentViewController:activityViewController animated:YES completion:nil];
+    
+    // 选中分享类型
+    [activityViewController setCompletionWithItemsHandler:^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
+        
+        // 显示选中的分享类型
+        NSLog(@"act type %@",activityType);
+        
+        if (completed) {
+            NSLog(@"ok");
+        }else {
+            NSLog(@"not ok");
+        }
+        
+    }];
+}
+
+- (void)quickLookMenuClick:(id)sender {
+    
+    UIAlertController *menuAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
+    
+    __weak typeof(self) weakSelf = self;
+    UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"Save Document" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        [weakSelf saveDocument];
+    }];
+    UIAlertAction *shareAction = [UIAlertAction actionWithTitle:@"Share Document" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+        [weakSelf shareDocument];
+    }];
+    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
+        
+    }];
+    
+    [menuAlert addAction:saveAction];
+    [menuAlert addAction:shareAction];
+    [menuAlert addAction:cancelAction];
+    
+    [self presentViewController:menuAlert animated:YES completion:nil];
+}
+
 @end