Sfoglia il codice sorgente

1.修改iOS Apex CRM选择联系人。

Pen Li 7 anni fa
parent
commit
25241518f3

+ 15 - 0
RedAnt CRM/APEX CRM/APEX CRM.xcodeproj/project.pbxproj

@@ -27,6 +27,7 @@
 		4212ABCC21AD450A00BE4E45 /* LPShareActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 4212ABCA21AD450900BE4E45 /* LPShareActivity.m */; };
 		4214C4A521B25EC20091A528 /* NSString+RAJavascript.m in Sources */ = {isa = PBXBuildFile; fileRef = 4214C4A421B25EC20091A528 /* NSString+RAJavascript.m */; };
 		4219F1DC21C1FE5400D81DDC /* UIView+RAConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 4219F1DB21C1FE5400D81DDC /* UIView+RAConstraint.m */; };
+		4232521721C491B600C77851 /* RAContactHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 4232521621C491B600C77851 /* RAContactHelper.m */; };
 		4277784F21AFB98600BCF7FA /* RAMapNavigateHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 4277784E21AFB98600BCF7FA /* RAMapNavigateHandler.m */; };
 		42A8A21321AE7828003B854B /* RAPhotoPreviewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 42A8A20B21AE7828003B854B /* RAPhotoPreviewController.m */; };
 		42A8A21421AE7828003B854B /* PhotoList.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 42A8A20D21AE7828003B854B /* PhotoList.storyboard */; };
@@ -100,6 +101,8 @@
 		4214C4A421B25EC20091A528 /* NSString+RAJavascript.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+RAJavascript.m"; sourceTree = "<group>"; };
 		4219F1DA21C1FE5400D81DDC /* UIView+RAConstraint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+RAConstraint.h"; sourceTree = "<group>"; };
 		4219F1DB21C1FE5400D81DDC /* UIView+RAConstraint.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+RAConstraint.m"; sourceTree = "<group>"; };
+		4232521521C491B600C77851 /* RAContactHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RAContactHelper.h; sourceTree = "<group>"; };
+		4232521621C491B600C77851 /* RAContactHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RAContactHelper.m; sourceTree = "<group>"; };
 		4277784D21AFB98600BCF7FA /* RAMapNavigateHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RAMapNavigateHandler.h; sourceTree = "<group>"; };
 		4277784E21AFB98600BCF7FA /* RAMapNavigateHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RAMapNavigateHandler.m; sourceTree = "<group>"; };
 		42A8A20A21AE7828003B854B /* RAPhotoPreviewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAPhotoPreviewController.h; sourceTree = "<group>"; };
@@ -284,6 +287,16 @@
 			path = ../../../common/LayoutConstraint;
 			sourceTree = "<group>";
 		};
+		4232521421C491A000C77851 /* Contact */ = {
+			isa = PBXGroup;
+			children = (
+				4232521521C491B600C77851 /* RAContactHelper.h */,
+				4232521621C491B600C77851 /* RAContactHelper.m */,
+			);
+			name = Contact;
+			path = ../../../common/Contact;
+			sourceTree = "<group>";
+		};
 		4277784C21AFB96700BCF7FA /* MapNavigation */ = {
 			isa = PBXGroup;
 			children = (
@@ -438,6 +451,7 @@
 		7106E80721A684F20056DD20 /* APEX CRM */ = {
 			isa = PBXGroup;
 			children = (
+				4232521421C491A000C77851 /* Contact */,
 				4219F1D921C1FE5400D81DDC /* LayoutConstraint */,
 				42F53F9521B65255008EAEFC /* PresentationController */,
 				42F53F8A21B651B6008EAEFC /* DatePicker */,
@@ -601,6 +615,7 @@
 				7106E82A21ABF2190056DD20 /* RAConvertor.m in Sources */,
 				7106E83A21AD1B070056DD20 /* mztools.c in Sources */,
 				4212AB8F21AD22AB00BE4E45 /* RAQRCodeScannerViewController.m in Sources */,
+				4232521721C491B600C77851 /* RAContactHelper.m in Sources */,
 				4212ABAA21AD36E600BE4E45 /* RAProgressHUD.m in Sources */,
 				4212AB9221AD22AB00BE4E45 /* RACameraViewController.m in Sources */,
 				7106E83C21AD1B070056DD20 /* ioapi.c in Sources */,

+ 2 - 0
RedAnt CRM/APEX CRM/APEX CRM/Info.plist

@@ -48,5 +48,7 @@
 		<string>UIInterfaceOrientationLandscapeLeft</string>
 		<string>UIInterfaceOrientationLandscapeRight</string>
 	</array>
+	<key>NSContactsUsageDescription</key>
+	<string>访问联系人</string>
 </dict>
 </plist>

+ 141 - 3
RedAnt CRM/APEX CRM/APEX CRM/RAWKWebView.m

@@ -23,6 +23,8 @@
 #import "NSString+RAJavascript.h"
 #import "SignatureViewController.h"
 #import "RADatePickerViewController.h"
+#import "RAContactHelper.h"
+#import <Contacts/Contacts.h>
 
 
 @interface RAWKWebView () <UINavigationControllerDelegate,UIImagePickerControllerDelegate,MFMailComposeViewControllerDelegate>
@@ -104,7 +106,7 @@
     [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"DatetimePicker"];
 
     [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"Signature"];
-
+    [self.wkwebView.configuration.userContentController addScriptMessageHandler:self name:@"SelectContact"];
 
     //    [self.configuration.userContentController addScriptMessageHandler:self name:@"Color"];
     //    [self.configuration.userContentController addScriptMessageHandler:self name:@"Pay"];
@@ -126,7 +128,7 @@
     [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"Navigation"];
     [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"DatetimePicker"];
     [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"Signature"];
-    
+    [self.wkwebView.configuration.userContentController removeScriptMessageHandlerForName:@"SelectContact"];
 }
 - (void)dealloc
 {
@@ -427,6 +429,134 @@
     }];
 }
 
+- (void)ra_selectContact:(NSDictionary *)params {
+
+    __weak typeof(self) weakSelf = self;
+    [[RAContactHelper defaultHelper] showContactPickerByViewController:self.ra_viewController withComplete:^(BOOL canceled, NSArray<CNContact *> *contacts) {
+        
+        if (!canceled) {
+            
+            NSMutableArray *contactArray = [NSMutableArray array];
+            for (CNContact *contact in contacts) {
+            
+                NSMutableDictionary *contactDictionary = [NSMutableDictionary dictionary];
+                NSLog(@"=========================================================");
+                // givenName middleName familyName
+                NSString *givenName = [self adjustNilString:contact.givenName];
+                NSString *middleName = [self adjustNilString:contact.middleName];
+                NSString *familyName = [self adjustNilString:contact.familyName];
+                NSString *name = [NSString stringWithFormat:@"%@ %@ %@", givenName, middleName, familyName];
+                
+                NSLog(@"=======================Contact Name=======================");
+                NSLog(@"%@",name);
+                contactDictionary[@"name"] = name;
+                
+                // organizationName departmentName jobTitle
+                NSString *organizationName = [self adjustNilString:contact.organizationName];
+                NSString *departmentName = [self adjustNilString:contact.departmentName];
+                NSString *jobTitle = [self adjustNilString:contact.jobTitle];
+                NSString *job = [NSString stringWithFormat:@"%@ %@ %@", organizationName, departmentName, jobTitle];
+                
+                NSLog(@"=======================Contact Job=======================");
+                NSLog(@"%@",job);
+                contactDictionary[@"job"] = job;
+                
+                // phoneNumbers emailAddresses postalAddresses urlAddresses
+                
+                NSMutableArray *phoneArray = [NSMutableArray array];
+                NSMutableArray *faxArray = [NSMutableArray array];
+                NSLog(@"=======================Phone Number=======================");
+                NSArray<CNLabeledValue<CNPhoneNumber*>*> *phoneNumbers = contact.phoneNumbers;
+                for (CNLabeledValue<CNPhoneNumber*> *labeledValue in phoneNumbers) {
+                    
+                    CNPhoneNumber *phoneNumber = labeledValue.value;
+                    NSString *label = [CNLabeledValue localizedStringForLabel:labeledValue.label];
+                    NSLog(@"%@ %@", label, phoneNumber.stringValue);
+                    
+                    if ([labeledValue.label.lowercaseString containsString:@"fax"]) {
+                        [faxArray addObject:phoneNumber.stringValue];
+                    } else {
+                        [phoneArray addObject:phoneNumber.stringValue];
+                    }
+                }
+                contactDictionary[@"phone"] = phoneArray;
+                contactDictionary[@"fax"] = faxArray;
+                
+                NSMutableArray *emailArray = [NSMutableArray array];
+                NSLog(@"=======================Email Address=======================");
+                NSArray<CNLabeledValue<NSString*>*> *emailAddresses = contact.emailAddresses;
+                for (CNLabeledValue<NSString*> *labeledValue in emailAddresses) {
+                    
+                    NSString *email = labeledValue.value;
+                    NSString *label = [CNLabeledValue localizedStringForLabel:labeledValue.label];
+                    NSLog(@"%@ %@", label, email);
+                    [emailArray addObject:email];
+                }
+                contactDictionary[@"email"] = emailArray;
+                
+                NSMutableArray *addressArray = [NSMutableArray array];
+                NSLog(@"=======================Postal Number=======================");
+                NSArray<CNLabeledValue<CNPostalAddress*>*> *postalAddresses = contact.postalAddresses;
+                for (CNLabeledValue<CNPostalAddress*> *labeledValue in postalAddresses) {
+                    
+                    NSString *label = [CNLabeledValue localizedStringForLabel:labeledValue.label];
+                    CNPostalAddress *postalAddress = labeledValue.value;
+                    NSString *postalCode = [self adjustNilString:postalAddress.postalCode];
+                    NSString *country = [self adjustNilString:postalAddress.country];
+                    NSString *state = [self adjustNilString:postalAddress.state];
+                    NSString *city = [self adjustNilString:postalAddress.city];
+                    NSString *street = [self adjustNilString:postalAddress.street];
+                    
+                    NSMutableDictionary *addressDic = [NSMutableDictionary dictionary];
+                    addressDic[@"postalCode"] = postalCode;
+                    addressDic[@"country"] = country;
+                    addressDic[@"state"] = state;
+                    addressDic[@"city"] = city;
+                    addressDic[@"street"] = street;
+                    
+                    [addressArray addObject:addressDic];
+                    NSLog(@"%@ %@ %@ %@ %@ %@", label, postalCode, country, state, city, street);
+                }
+                contactDictionary[@"address"] = addressArray;
+                
+                NSMutableArray *urlArray = [NSMutableArray array];
+                NSLog(@"=======================URL Address=======================");
+                NSArray<CNLabeledValue<NSString*>*> *urlAddresses = contact.urlAddresses;
+                for (CNLabeledValue<NSString*> *labeledValue in urlAddresses) {
+                    
+                    NSString *url = labeledValue.value;
+                    NSString *label = [CNLabeledValue localizedStringForLabel:labeledValue.label];
+                    NSLog(@"%@ %@", label, url);
+                    
+                    [urlArray addObject:url];
+                }
+                contactDictionary[@"url"] = urlArray;
+                
+                NSLog(@"**********************************************************");
+                
+                [contactArray addObject:contactDictionary];
+            }
+            
+            // return
+            
+            NSString *jsonString = [RAConvertor DataTOjsonString:contactArray];
+            [weakSelf returnToWebPage:params value:jsonString];
+            
+            NSLog(@"%@", jsonString);
+        }
+        
+    }];
+}
+
+#pragma mark - Utils
+
+- (NSString *)adjustNilString:(NSString *)str {
+    if (str) {
+        return str;
+    }
+    return @"";
+}
+
 #pragma mark - Web Callback
 
 -(void) returnToWebPage:(NSDictionary*)params value:(NSObject*)value
@@ -610,8 +740,10 @@
         
         
         [self handleDatetimePicker:params];
+    } else if ([message.name isEqualToString:@"SelectContact"]) {
+        
+        [self handleSelectContact:params];
     }
-    
     else
     {
         NSLog(@"%@",params);
@@ -723,6 +855,11 @@
     
 }
 
+- (void)handleSelectContact:(NSDictionary *)params {
+    
+    [self ra_selectContact:params];
+}
+
 #pragma mark - WKNavigationDelegate
 
 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
@@ -828,4 +965,5 @@
     NSLog(@"%s",__func__);
     decisionHandler(WKNavigationResponsePolicyAllow);
 }
+
 @end

+ 1 - 1
RedAnt CRM/APEX CRM/APEX CRM/ViewController.m

@@ -29,7 +29,7 @@
 
 //    vc.url = @"http://192.168.0.124:8081/j/crm/mobile/login";
     
-    vc.url = @"http://192.168.0.130:8080/MyWeb/html/test.html";
+    vc.url = @"http://192.168.0.139:8080/MyWeb/html/test.html";
     
     
     

+ 1 - 1
RedAnt CRM/APEX CRM/APEX CRM/WKWebTestViewController.m

@@ -19,7 +19,7 @@
 - (void)viewDidLoad {
     [super viewDidLoad];
     
-    self.navigationController.navigationBar.hidden =true;
+//    self.navigationController.navigationBar.hidden =true;
     
     [UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor whiteColor];