Ver código fonte

1.修改Apex CRM拍照、分享以及邮件回调。

Pen Li 7 anos atrás
pai
commit
c33ed9d2c6
1 arquivos alterados com 45 adições e 14 exclusões
  1. 45 14
      RedAnt CRM/APEX CRM/APEX CRM/RAWKWebView.m

+ 45 - 14
RedAnt CRM/APEX CRM/APEX CRM/RAWKWebView.m

@@ -23,7 +23,10 @@
 
 
 @interface RAWKWebView () <UINavigationControllerDelegate,UIImagePickerControllerDelegate,MFMailComposeViewControllerDelegate>
-@property (strong, nonatomic)   WKWebView                   *wkwebView;
+
+@property (strong, nonatomic) WKWebView *wkwebView;
+@property (nonatomic,strong) NSDictionary *currentParams;
+
 @end
 
 @implementation RAWKWebView
@@ -139,6 +142,7 @@
     imagePicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
     imagePicker.allowsEditing = YES;
     [self.ra_viewController presentViewController:imagePicker animated:YES completion:nil];
+    self.currentParams = params;
 }
 
 - (void)ra_openCamera:(NSDictionary *)params {
@@ -146,6 +150,14 @@
     RACameraViewController *cameraVC = [RACameraViewController viewControllerFromStoryboard];
     cameraVC.completion = ^(UIImage *image) {
 
+        NSData *data = UIImageJPEGRepresentation(image, 1.0);
+//        NSString *name = NSUUID.UUID.UUIDString;
+//        NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:name];
+//        [data writeToFile:path atomically:NO];
+        
+        NSString *imageSource = [NSString stringWithFormat:@"data:image/jpg;base64,%@",[data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]];
+        
+        [self returnToWebPage:params value:imageSource];
     };
     
     cameraVC.fromVC = self.ra_viewController;
@@ -231,7 +243,6 @@
      subject = "email subject";
      
      */
-
     MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
     
     if(mc==nil)
@@ -269,7 +280,7 @@
 //    [mc addAttachmentData:data mimeType:@"application/pdf" fileName:filename];
     
     [self.ra_viewController presentViewController:mc animated:YES completion:nil];
-    
+    self.currentParams = params;
 }
 
 - (void)ra_share:(NSDictionary *)params {
@@ -301,12 +312,22 @@
         // 显示选中的分享类型
         NSLog(@"act type %@",activityType);
         
-        if (completed) {
-            NSLog(@"ok");
-        }else {
-            NSLog(@"not ok");
-
+//        if (completed) {
+//            NSLog(@"ok");
+//        }else {
+//            NSLog(@"not ok");
+//        }
+        NSMutableDictionary *shareResult = [NSMutableDictionary dictionary];
+        if (!activityType) {
+            activityType = @"cancel";
         }
+        shareResult[@"to"] = [activityType componentsSeparatedByString:@"."].lastObject;
+        shareResult[@"completed"] = @(completed);
+        if (activityError) {
+            shareResult[@"error"] = activityError.localizedDescription;
+        }
+        
+        [self returnToWebPage:params value:[RAConvertor dict2string:shareResult]];
         
     }];
     
@@ -378,23 +399,28 @@
 #pragma mark - MFMailComposeViewControllerDelegate delegate
 
 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
+    NSString *resultStr = nil;
     switch (result)
     {
         case MFMailComposeResultCancelled:
-            DebugLog(@"Mail send canceled...");
+            resultStr = @"email canceled";
             break;
         case MFMailComposeResultSaved:
-            DebugLog(@"Mail saved...");
+            resultStr = @"email saved";
             break;
         case MFMailComposeResultSent:
-            DebugLog(@"Mail sent...");
+            resultStr = @"email send";
             break;
         case MFMailComposeResultFailed:
-            DebugLog(@"Mail send errored: %@...", [error localizedDescription]);
+            resultStr = [NSString stringWithFormat:@"email error: %@",[error localizedDescription]];
             break;
         default:
             break;
     }
+    
+    [self returnToWebPage:self.currentParams value:resultStr];
+    self.currentParams = nil;
+    
     [controller dismissViewControllerAnimated:YES completion:nil];
 }
 
@@ -407,9 +433,14 @@
         
         UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
         [picker dismissViewControllerAnimated:YES completion:nil];
-        NSLog(@"select image %@", image);
+        
+        NSData *data = UIImageJPEGRepresentation(image, 1.0);
+        NSString *imageSource = [NSString stringWithFormat:@"data:image/jpg;base64,%@",[data base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]];
+
+        [self returnToWebPage:self.currentParams value:imageSource];
+        self.currentParams = nil;
+        
     }
-    
 }
 
 - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {