Bläddra i källkod

1.修改iOS Apex Mobile Communitaction CC联系人选择。

Pen Li 8 år sedan
förälder
incheckning
3ca023aeec

+ 6 - 0
Apex Mobile/Apex Mobile.xcodeproj/project.pbxproj

@@ -56,6 +56,7 @@
 		42BCACCA209AE243009DDA43 /* AMAnnotationView.m in Sources */ = {isa = PBXBuildFile; fileRef = 42BCACC9209AE243009DDA43 /* AMAnnotationView.m */; };
 		42BCACCD209AE342009DDA43 /* AMMapAnnotaion.m in Sources */ = {isa = PBXBuildFile; fileRef = 42BCACCC209AE342009DDA43 /* AMMapAnnotaion.m */; };
 		42BFD2D2207B697800DA9038 /* KPICell.m in Sources */ = {isa = PBXBuildFile; fileRef = 42BFD2D1207B697800DA9038 /* KPICell.m */; };
+		42DE626220A41907005FB582 /* AMTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 42DE626120A41907005FB582 /* AMTextField.m */; };
 		7101BEC82031389A00CC6E3A /* DetailCellKVNew.m in Sources */ = {isa = PBXBuildFile; fileRef = 7101BEC72031389A00CC6E3A /* DetailCellKVNew.m */; };
 		711BA6C1191E0525002EDE6F /* MessageViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 711BA6C0191E0525002EDE6F /* MessageViewController.m */; };
 		711BA6C4191E0553002EDE6F /* MessageItem.m in Sources */ = {isa = PBXBuildFile; fileRef = 711BA6C3191E0553002EDE6F /* MessageItem.m */; };
@@ -277,6 +278,8 @@
 		42BCACCC209AE342009DDA43 /* AMMapAnnotaion.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AMMapAnnotaion.m; sourceTree = "<group>"; };
 		42BFD2D0207B697800DA9038 /* KPICell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KPICell.h; sourceTree = "<group>"; };
 		42BFD2D1207B697800DA9038 /* KPICell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = KPICell.m; sourceTree = "<group>"; };
+		42DE626020A41907005FB582 /* AMTextField.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AMTextField.h; sourceTree = "<group>"; };
+		42DE626120A41907005FB582 /* AMTextField.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AMTextField.m; sourceTree = "<group>"; };
 		7101BEC62031389A00CC6E3A /* DetailCellKVNew.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DetailCellKVNew.h; sourceTree = "<group>"; };
 		7101BEC72031389A00CC6E3A /* DetailCellKVNew.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = DetailCellKVNew.m; sourceTree = "<group>"; };
 		711BA6BF191E0525002EDE6F /* MessageViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageViewController.h; sourceTree = "<group>"; };
@@ -560,6 +563,8 @@
 				420DEF2D20A189AA00720524 /* AMCommEditCell.h */,
 				420DEF2E20A189AA00720524 /* AMCommEditCell.m */,
 				420DEF2F20A189AA00720524 /* AMCommEditCell.xib */,
+				42DE626020A41907005FB582 /* AMTextField.h */,
+				42DE626120A41907005FB582 /* AMTextField.m */,
 			);
 			name = Communication;
 			sourceTree = "<group>";
@@ -1437,6 +1442,7 @@
 				712A301318CFEF550022E6E6 /* CustomizeFieldViewController.m in Sources */,
 				715709BD20215E0000EFE5C5 /* AESCrypt.m in Sources */,
 				716FF7921904ED2600ED6C3D /* NewsData.m in Sources */,
+				42DE626220A41907005FB582 /* AMTextField.m in Sources */,
 				71F67CF619063612004E8462 /* ApexHistoryViewController.m in Sources */,
 				7130B3F41900FB61000610D8 /* NewsViewController.m in Sources */,
 				711BA6C1191E0525002EDE6F /* MessageViewController.m in Sources */,

+ 4 - 0
Apex Mobile/Apex Mobile/AMCommHeadCell.h

@@ -15,6 +15,7 @@
 - (void)commHeadCell:(AMCommHeadCell *)cell didChangeCC:(NSString *)cc;
 - (void)commHeadCell:(AMCommHeadCell *)cell didBeginEditing:(UITextField *)textField;
 - (void)commHeadCell:(AMCommHeadCell *)cell didEndEditing:(UITextField *)textField;
+- (void)commHeadCell:(AMCommHeadCell *)cell didClickContactButton:(UIButton *)button;
 
 @end
 
@@ -25,4 +26,7 @@
 @property (nonatomic,copy) NSString *to;
 @property (nonatomic,copy) NSString *cc;
 
+
+- (void)beginEditing;
+
 @end

+ 20 - 0
Apex Mobile/Apex Mobile/AMCommHeadCell.m

@@ -22,6 +22,13 @@
     // Initialization code
     
     self.ccTextField.delegate = self;
+    
+    UIButton *contactBtn = [UIButton buttonWithType:UIButtonTypeCustom];
+    contactBtn.frame = CGRectMake(0, 0, 30, 30);
+    [contactBtn setImage:[UIImage imageNamed:@"ic_contact"] forState:UIControlStateNormal];
+    [contactBtn addTarget:self action:@selector(contactBtnClick:) forControlEvents:UIControlEventTouchUpInside];
+    self.ccTextField.rightView = contactBtn;
+    self.ccTextField.rightViewMode = UITextFieldViewModeAlways;
 }
 
 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
@@ -40,6 +47,19 @@
     self.ccTextField.text = _cc;
 }
 
+- (void)beginEditing {
+    [self.ccTextField becomeFirstResponder]; // 光标移动到最后
+}
+
+#pragma mark - Action
+
+- (void)contactBtnClick:(UIButton *)sender {
+    
+    if (self.delegate && [self.delegate respondsToSelector:@selector(commHeadCell:didClickContactButton:)]) {
+        [self.delegate commHeadCell:self didClickContactButton:sender];
+    }
+}
+
 #pragma mark - Delegate
 
 - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

+ 1 - 1
Apex Mobile/Apex Mobile/AMCommHeadCell.xib

@@ -37,7 +37,7 @@
                         <color key="textColor" red="1" green="0.1047433005" blue="0.075207091899999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                         <nil key="highlightedColor"/>
                     </label>
-                    <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="uaj-Fd-5wB">
+                    <textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="uaj-Fd-5wB" customClass="AMTextField">
                         <rect key="frame" x="5" y="79" width="484" height="30"/>
                         <nil key="textColor"/>
                         <fontDescription key="fontDescription" type="system" pointSize="14"/>

+ 13 - 0
Apex Mobile/Apex Mobile/AMTextField.h

@@ -0,0 +1,13 @@
+//
+//  AMTextField.h
+//  Apex Mobile
+//
+//  Created by Jack on 2018/5/10.
+//  Copyright © 2018年 United Software Applications, Inc. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface AMTextField : UITextField
+
+@end

+ 25 - 0
Apex Mobile/Apex Mobile/AMTextField.m

@@ -0,0 +1,25 @@
+//
+//  AMTextField.m
+//  Apex Mobile
+//
+//  Created by Jack on 2018/5/10.
+//  Copyright © 2018年 United Software Applications, Inc. All rights reserved.
+//
+
+#import "AMTextField.h"
+
+@implementation AMTextField
+
+- (CGRect)textRectForBounds:(CGRect)bounds {
+    CGRect rect = [super textRectForBounds:bounds];
+    
+    return rect;
+}
+
+- (CGRect)editingRectForBounds:(CGRect)bounds {
+    CGRect rect = [super editingRectForBounds:bounds];
+    
+    return rect;
+}
+
+@end

+ 121 - 12
Apex Mobile/Apex Mobile/DetailPageViewController.m

@@ -26,6 +26,9 @@
 #import "AMCommHeadCell.h"
 #import "AMCommContentCell.h"
 
+#import <Contacts/Contacts.h>
+#import <ContactsUI/ContactsUI.h>
+
 #define COMM_ID_HEAD @"COMM_ID_HEAD"
 #define COMM_ID_CONTENT @"COMM_ID_CONTENT"
 #define COMM_ID_EDIT @"COMM_ID_EDIT"
@@ -112,7 +115,7 @@
 
 @end
 
-@interface DetailPageViewController () <QLPreviewControllerDataSource,QLPreviewControllerDelegate,DetailKVCellTapDelegate,AMCommHeadCellDelegate,AMCommContentCellDelegate,AMCommEditCellDelegate>
+@interface DetailPageViewController () <QLPreviewControllerDataSource,QLPreviewControllerDelegate,DetailKVCellTapDelegate,AMCommHeadCellDelegate,AMCommContentCellDelegate,AMCommEditCellDelegate,CNContactPickerDelegate>
 
 @property (nonatomic,strong) MyQLPreviewController *quickLook;
 @property (nonatomic,copy) NSString *documentPath;
@@ -125,6 +128,7 @@
 
 @property (nonatomic,weak) UITableViewCell *editingCell;
 @property (nonatomic,strong) NSIndexPath *editingIndexPath;
+@property (nonatomic,strong) NSIndexPath *contactSelectIndexPath;
 @property (nonatomic,weak) UITapGestureRecognizer *tap;
 @property (nonatomic,assign) BOOL showKeyboard;
 
@@ -311,6 +315,9 @@
     if (self.showMap) {
         [self.params setObject:@(YES) forKey:@"request_location"];
     }
+    if ([[self.params objectForKey:@"action_type"] isEqualToString:@"Detail"]) {
+        [self.params setObject:@(YES) forKey:@"request_communication"];
+    }
     
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
         
@@ -1645,16 +1652,7 @@
     
     NSIndexPath *indexPath = [self.table indexPathForCell:cell];
     
-    NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
-    if (cc && cc.length > 0) {
-        [segment setValue:cc forKey:@"cc"];
-    } else {
-        [segment removeObjectForKey:@"cc"];
-    }
-    
-    NSMutableArray *arr = [self.content.segments mutableCopy];
-    [arr replaceObjectAtIndex:indexPath.section withObject:segment];
-    self.content.segments = arr;
+    [self cc:cc changedForIndexPath:indexPath];
 }
 
 - (void)commHeadCell:(AMCommHeadCell *)cell didBeginEditing:(UITextField *)textField {
@@ -1667,10 +1665,35 @@
     self.editingIndexPath = nil;
 }
 
+- (void)commHeadCell:(AMCommHeadCell *)cell didClickContactButton:(UIButton *)button {
+    
+    self.contactSelectIndexPath = [self.table indexPathForCell:cell];
+    
+    CNContactPickerViewController *contactVC = [[CNContactPickerViewController alloc] init];
+    contactVC.delegate = self;
+    
+    
+    [self presentViewController:contactVC animated:YES completion:nil];
+}
+
 #pragma mark - COMM Content Delegate
 
 - (void)commContentCell:(AMCommContentCell *)cell sendEmail:(NSString *)email {
     
+//    MFMailComposeViewController *emailVC = [[MFMailComposeViewController alloc] init];
+//    if (!emailVC) {
+//
+//        return;
+//    }
+//    [emailVC setMessageBody:[NSString stringWithFormat:@"<a>%@</a>",email] isHTML:YES];
+//
+//    [self presentViewController:emailVC animated:YES completion:nil];
+    
+    NSURL *url = [NSURL URLWithString:email];
+    if ([[UIApplication sharedApplication] canOpenURL:url]) {
+        [[UIApplication sharedApplication] openURL:url];
+    }
+    
 }
 
 #pragma mark - COMM Edit Delegate
@@ -1718,9 +1741,11 @@
     UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"send email" preferredStyle:UIAlertControllerStyleAlert];
     [self presentViewController:alert animated:YES completion:nil];
     
+    NSString *serialNo = [segment objectForKey:@"serial_no"];
+    
     __weak typeof(self) weakSelf = self;
     dispatch_async(dispatch_get_global_queue(0, 0), ^{
-        NSDictionary *sendResponse = [RANetwork sendEmail:email CC:cc];
+        NSDictionary *sendResponse = [RANetwork sendEmail:email CC:cc SerialNo:serialNo];
         dispatch_async(dispatch_get_main_queue(), ^{
             
             [alert dismissViewControllerAnimated:YES completion:^{
@@ -1790,6 +1815,40 @@
     self.editingIndexPath = nil;
 }
 
+#pragma mark - Contact Picker Delegate
+
+- (void)contactPickerDidCancel:(CNContactPickerViewController *)picker {
+
+    self.contactSelectIndexPath = nil;
+}
+
+- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact {
+    
+    [self handleSelectContact:contact];
+    
+    self.contactSelectIndexPath = nil;
+}
+
+- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContacts:(NSArray<CNContact *> *)contacts {
+    
+    for (CNContact *contact in contacts) {
+        [self handleSelectContact:contact];
+    }
+    
+    self.contactSelectIndexPath = nil;
+}
+
+- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperty:(CNContactProperty *)contactProperty {
+
+    self.contactSelectIndexPath = nil;
+}
+
+- (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperties:(NSArray<CNContactProperty *> *)contactProperties {
+    
+    self.contactSelectIndexPath = nil;
+}
+
+
 #pragma mark - Utils
 
 - (BOOL)validateEmail:(NSString *)email {
@@ -1801,4 +1860,54 @@
     return [emailTest evaluateWithObject:email];
 }
 
+- (void)handleSelectContact:(CNContact *)contact {
+    
+    NSArray *emailArr = [contact emailAddresses];
+    for (CNLabeledValue *value in emailArr) {
+        if ([value.label isEqualToString:CNLabelWork]) {
+            [self appendCC:[NSString stringWithFormat:@"%@;",value.value] forIndexPath:self.contactSelectIndexPath];
+            [self.table reloadRowsAtIndexPaths:@[self.contactSelectIndexPath] withRowAnimation:UITableViewRowAnimationNone];
+            AMCommHeadCell *cell = [self.table cellForRowAtIndexPath:self.contactSelectIndexPath];
+            [cell beginEditing];
+            break;
+        }
+    }
+    
+}
+
+- (void)appendCC:(NSString *)cc forIndexPath:(NSIndexPath *)indexPath {
+    if (indexPath == nil || cc == nil || cc.length == 0) {
+        return;
+    }
+    NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
+    NSString *oldCC = [segment objectForKey:@"cc"];
+    if (oldCC == nil) {
+        oldCC = cc;
+    } else {
+        if ([[oldCC substringFromIndex:oldCC.length - 1] isEqualToString:@";"]) {
+            oldCC = [oldCC stringByAppendingString:cc];
+        } else {
+            oldCC = [oldCC stringByAppendingString:[NSString stringWithFormat:@";%@",cc]];
+        }
+    }
+    
+    [self cc:oldCC changedForIndexPath:indexPath];
+}
+
+- (void)cc:(NSString *)cc changedForIndexPath:(NSIndexPath *)indexPath {
+    if (indexPath == nil) {
+        return;
+    }
+    NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
+    if (cc && cc.length > 0) {
+        [segment setValue:cc forKey:@"cc"];
+    } else {
+        [segment removeObjectForKey:@"cc"];
+    }
+    
+    NSMutableArray *arr = [self.content.segments mutableCopy];
+    [arr replaceObjectAtIndex:indexPath.section withObject:segment];
+    self.content.segments = arr;
+}
+
 @end

+ 23 - 0
Apex Mobile/Apex Mobile/NewImages.xcassets/ic_contact.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "ic_contact.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_contact@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "ic_contact@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/ic_contact.imageset/ic_contact.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/ic_contact.imageset/ic_contact@2x.png


BIN
Apex Mobile/Apex Mobile/NewImages.xcassets/ic_contact.imageset/ic_contact@3x.png


+ 1 - 1
Apex Mobile/Apex Mobile/RANetwork.h

@@ -42,6 +42,6 @@
 + (NSDictionary *)requestOrderHistory:(NSMutableDictionary *)params;
 + (void)download_file:(NSMutableDictionary *)params url:(NSString *)url toCachePath:(NSString *)path progressHandler:(progressHandler)progressHandler completionHandler:(resultHandler)result;
 + (NSDictionary *)requestKPI;
-+ (NSDictionary *)sendEmail:(NSString *)email CC:(NSString *)cc;
++ (NSDictionary *)sendEmail:(NSString *)email CC:(NSString *)cc SerialNo:(NSString *)serialNo;
 
 @end

+ 34 - 28
Apex Mobile/Apex Mobile/RANetwork.m

@@ -477,32 +477,32 @@
         
         int count =[[jsobj valueForKey:@"count"] intValue];
         
-        if ([[params objectForKey:@"action_type"] isEqualToString:@"Detail"]) {
-            NSMutableDictionary *mJson = [jsobj mutableCopy];
-            NSDictionary *comm = @{
-                                   @"_name": @"Communication",
-                                   @"_type": @"communication",
-                                   @"cc": @"",
-                                   @"receipt": @"",
-                                   @"count": @2,
-                                   @"item0": @{
-                                           @"Sender": @"user name",
-                                           @"msg": @"content bla bla bla...",
-                                           @"mst_time": @"04/28/2018 20:15:33",
-                                           @"email_url": @"https://..."
-                                           },
-                                   @"item1": @{
-                                           @"Sender": @"user name",
-                                           @"msg": @"content bla bla bla...",
-                                           @"mst_time": @"04/28/2018 20:15:33"
-                                           }
-                                   };
-            [mJson setObject:comm forKey:[NSString stringWithFormat:@"group%d",count]];
-            
-            [mJson setObject:@(++count) forKey:@"count"];
-            
-            jsobj = mJson;
-        }
+//        if ([[params objectForKey:@"action_type"] isEqualToString:@"Detail"]) {
+//            NSMutableDictionary *mJson = [jsobj mutableCopy];
+//            NSDictionary *comm = @{
+//                                   @"_name": @"Communication",
+//                                   @"_type": @"communication",
+//                                   @"cc": @"",
+//                                   @"receipt": @"",
+//                                   @"count": @2,
+//                                   @"item0": @{
+//                                           @"Sender": @"user name",
+//                                           @"msg": @"content bla bla bla...",
+//                                           @"mst_time": @"04/28/2018 20:15:33",
+//                                           @"email_url": @"https://www.baidu.com"
+//                                           },
+//                                   @"item1": @{
+//                                           @"Sender": @"user name",
+//                                           @"msg": @"content bla bla bla...",
+//                                           @"mst_time": @"04/28/2018 20:15:33"
+//                                           }
+//                                   };
+//            [mJson setObject:comm forKey:[NSString stringWithFormat:@"group%d",count]];
+//
+//            [mJson setObject:@(++count) forKey:@"count"];
+//
+//            jsobj = mJson;
+//        }
         
         detailContent.result_code = RESULT_TRUE;
         if(count==0)
@@ -1323,15 +1323,21 @@
     
 }
 
-+ (NSDictionary *)sendEmail:(NSString *)email CC:(NSString *)cc {
++ (NSDictionary *)sendEmail:(NSString *)email CC:(NSString *)cc SerialNo:(NSString *)serialNo {
     
     if (!email) {
         email = @"";
     }
+    if (!serialNo) {
+        serialNo = @"";
+    }
     
     NSMutableDictionary *params = [NSMutableDictionary dictionary];
-//    [params setObject:@"hand_new_kpi" forKey:@"action"];
+    [params setObject:@"handset_search" forKey:@"action"];
+    [params setObject:@"save_communication_email" forKey:@"action_type"];
+    [params setObject:serialNo forKey:@"serial_no"];
     [params setObject:email forKey:@"msg"];
+    
     if (cc) {
         [params setObject:cc forKey:@"cc"];
     }

+ 2 - 2
Apex Mobile/Apex Mobile/config.h

@@ -33,7 +33,7 @@
 #define URL_PUSH                @"http://192.168.2.138/Online/Online/main_new.php"
 #define URL_KPI                 @"http://192.168.2.138/Online/Online/main_new.php"
 #define URL_ERR_LOG             @""
-#define URL_SEND_COMM_EMAIL     @""
+#define URL_SEND_COMM_EMAIL     @"http://192.168.2.138/Online/Online/main_new.php"
 
 
 #else
@@ -51,7 +51,7 @@
 #define URL_PUSH                @"https://ra.apexshipping.com/main_new.php"
 #define URL_KPI                 @"https://ra.apexshipping.com/main_new.php"
 #define URL_ERR_LOG             @""
-#define URL_SEND_COMM_EMAIL     @""
+#define URL_SEND_COMM_EMAIL     @"https://ra.apexshipping.com/main_new.php"
 
 #endif