瀏覽代碼

1.修改iOS Apex Mobile Communitaction发送Email。

Pen Li 8 年之前
父節點
當前提交
ed44babe60

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

@@ -41,7 +41,7 @@
                         <rect key="frame" x="5" y="79" width="484" height="30"/>
                         <nil key="textColor"/>
                         <fontDescription key="fontDescription" type="system" pointSize="14"/>
-                        <textInputTraits key="textInputTraits"/>
+                        <textInputTraits key="textInputTraits" autocorrectionType="no"/>
                     </textField>
                     <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="separated by ;" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Zx3-At-l7K">
                         <rect key="frame" x="408" y="114" width="81" height="14.5"/>

+ 86 - 0
Apex Mobile/Apex Mobile/DetailPageViewController.m

@@ -1677,6 +1677,81 @@
 
 - (void)commEditCell:(AMCommEditCell *)cell clickToSendEmail:(NSString *)email {
     
+    // 检查Email内容是否为空
+    if (!email || email.length == 0) {
+        
+        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"The communication message that will be sent is blank" preferredStyle:UIAlertControllerStyleAlert];
+        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+            
+        }];
+        [alert addAction:okAction];
+        [self presentViewController:alert animated:YES completion:nil];
+        return;
+    }
+    
+    NSIndexPath *indexPath = [self.table indexPathForCell:cell];
+    NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
+    NSString *cc = [segment objectForKey:@"cc"];
+    if (cc && cc.length > 0) {
+        
+        // 校验邮箱地址格式是否有效
+        NSArray *ccArr = [cc componentsSeparatedByString:@";"];
+        for (NSString *ccStr in ccArr) {
+            if (ccStr.length > 0) {
+                BOOL isEmail = [self validateEmail:ccStr];
+                if (!isEmail) {
+                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"The communication cc is not right" preferredStyle:UIAlertControllerStyleAlert];
+                    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                        
+                    }];
+                    [alert addAction:okAction];
+                    [self presentViewController:alert animated:YES completion:nil];
+                    return;
+                }
+            }
+        }
+        
+        // 校验通过
+        
+    }
+    
+    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"send email" preferredStyle:UIAlertControllerStyleAlert];
+    [self presentViewController:alert animated:YES completion:nil];
+    
+    __weak typeof(self) weakSelf = self;
+    dispatch_async(dispatch_get_global_queue(0, 0), ^{
+        NSDictionary *sendResponse = [RANetwork sendEmail:email CC:cc];
+        dispatch_async(dispatch_get_main_queue(), ^{
+            
+            [alert dismissViewControllerAnimated:YES completion:^{
+                
+                if (weakSelf) {
+                    __strong typeof(weakSelf) strongSelf = weakSelf;
+                    int result = [[sendResponse objectForKey:@"result"] intValue];
+                    
+                    if (result == RESULT_TRUE) {
+                        
+                    } else {
+                        NSString *msg = [sendResponse objectForKey:@"err_msg"];
+                        if (msg == nil) {
+                            msg = @"Sorry,something wrong";
+                        }
+                        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:msg preferredStyle:UIAlertControllerStyleAlert];
+                        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
+                            
+                        }];
+                        [alert addAction:okAction];
+                        [strongSelf presentViewController:alert animated:YES completion:nil];
+                    }
+                    
+                }
+                
+            }];
+            
+        });
+    });
+    
+    
 }
 
 - (void)commEditCell:(AMCommEditCell *)cell didChangeEmail:(NSString *)email {
@@ -1715,4 +1790,15 @@
     self.editingIndexPath = nil;
 }
 
+#pragma mark - Utils
+
+- (BOOL)validateEmail:(NSString *)email {
+    
+    NSString *emailRegex =@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
+    
+    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
+    
+    return [emailTest evaluateWithObject:email];
+}
+
 @end

+ 2 - 0
Apex Mobile/Apex Mobile/RANetwork.h

@@ -42,4 +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;
+
 @end

+ 30 - 0
Apex Mobile/Apex Mobile/RANetwork.m

@@ -1323,4 +1323,34 @@
     
 }
 
++ (NSDictionary *)sendEmail:(NSString *)email CC:(NSString *)cc {
+    
+    if (!email) {
+        email = @"";
+    }
+    
+    NSMutableDictionary *params = [NSMutableDictionary dictionary];
+//    [params setObject:@"hand_new_kpi" forKey:@"action"];
+    [params setObject:email forKey:@"msg"];
+    if (cc) {
+        [params setObject:cc forKey:@"cc"];
+    }
+    
+    
+    NSData* json=[self get_json:URL_SEND_COMM_EMAIL parameters:params  file:nil];
+    
+    if (json==nil)
+    {
+        return @{
+                 @"result" : @RESULT_NET_ERROR,
+                 @"err_msg" : MSG_NET_ERROR
+                 };
+    }
+    
+    NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:json options:NSJSONReadingMutableLeaves error:nil];
+    
+    return resultDic;
+    
+}
+
 @end

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

@@ -33,6 +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     @""
 
 
 #else
@@ -50,6 +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     @""
 
 #endif