Commit 028d32ac184456c1930c3f5dd8db636f2ce9b908

Authored by Cao yang
2 parents 684fa2de 742737c2
Exists in parentassistant

Merge branch 'parentassistant' of http://git.shunzhi.net/iosgroup/parentassistan…

…t into parentassistant
ParentAssistant/ParentAssistant/Classes/controllers/main/TabBarController.swift
... ... @@ -12,6 +12,7 @@ class TabBarController: UITabBarController {
12 12  
13 13 override func viewDidLoad() {
14 14 super.viewDidLoad()
  15 + updataVersion()
15 16 }
16 17  
17 18 override func didReceiveMemoryWarning() {
... ... @@ -29,5 +30,116 @@ class TabBarController: UITabBarController {
29 30 // Pass the selected object to the new view controller.
30 31 }
31 32 */
  33 + func updataVersion(_ isRemain:Bool=false){
  34 + let request = NSMutableURLRequest(url: URL(string: "http://itunes.apple.com/lookup?id=1357945086")!, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringCacheData, timeoutInterval: 10)
  35 + request.httpMethod = "POST"
  36 + // NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: OperationQueue.main, completionHandler: { (respones, data, error) in
  37 + let config=URLSessionConfiguration.default
  38 + let session=URLSession(configuration: config, delegate: self, delegateQueue: nil)
  39 + let dataTask=session.dataTask(with: request as URLRequest, completionHandler: { (data, response, sessionError) in
  40 + if let datas = data{
  41 + do{
  42 + let dictionary = try JSONSerialization.jsonObject(with: datas, options: JSONSerialization.ReadingOptions.mutableLeaves)
  43 + if ((dictionary as! NSDictionary)["resultCount"] as AnyObject).int32Value > 0{
  44 + let dataInformatica = ((dictionary as! NSDictionary)["results"] as! NSArray)[0] as! NSDictionary
  45 + let version = dataInformatica["version"]! as! String
  46 + if UIApplication.appVersion() < version{
  47 + let alert = UIAlertController(title: "发现新版本", message: dataInformatica["releaseNotes"]! as? String, preferredStyle: .alert)
  48 + alert.addAction(UIAlertAction(title: "前往更新", style: .default, handler: { (action) in
  49 + // UIApplication.shared.openURL(URL(string: "itms-apps://itunes.apple.com/app/id1271291794")!)
  50 + UIApplication.shared.open(URL(string: "itms-apps://itunes.apple.com/app/id1357945086")!, options: [:], completionHandler: nil)
  51 + }))
  52 + alert.addAction(UIAlertAction(title: "以后再说", style: .cancel, handler: { (action) in
  53 +
  54 + }))
  55 + self.present(alert, animated: true, completion: nil)
  56 + }else{
  57 + if isRemain{
  58 + appDelegate.window?.makeToast("已经是最新版本")
  59 + }
  60 + NSLog("不需要更新")
  61 + }
  62 + }
  63 + }
  64 + catch let error as NSError {
  65 + NSLog("请求失败")
  66 + appDelegate.window?.makeToast(error.localizedDescription)
  67 + }
  68 + }
  69 + })
  70 + dataTask.resume()
  71 + }
  72 +}
  73 +extension TabBarController: URLSessionDelegate {
  74 + func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
  75 + //认证服务器证书
  76 + if challenge.protectionSpace.authenticationMethod
  77 + == (NSURLAuthenticationMethodServerTrust) {
  78 + print("服务端证书认证!")
  79 + completionHandler(.performDefaultHandling, nil)
  80 + }
  81 + //认证客户端证书
  82 + else if challenge.protectionSpace.authenticationMethod
  83 + == NSURLAuthenticationMethodClientCertificate
  84 + {
  85 + print("客户端证书认证!")
  86 + //获取客户端证书相关信息
  87 + let identityAndTrust:IdentityAndTrust = self.extractIdentity();
  88 +
  89 + let urlCredential:URLCredential = URLCredential(
  90 + identity: identityAndTrust.identityRef,
  91 + certificates: identityAndTrust.certArray as? [AnyObject],
  92 + persistence: URLCredential.Persistence.forSession);
  93 +
  94 + completionHandler(.useCredential, urlCredential);
  95 + }
  96 +
  97 + // 其它情况(不接受认证)
  98 + else {
  99 + print("其它情况(不接受认证)")
  100 + completionHandler(.cancelAuthenticationChallenge, nil);
  101 + }
  102 + }
  103 + //获取客户端证书相关信息
  104 + func extractIdentity() -> IdentityAndTrust {
  105 + var identityAndTrust:IdentityAndTrust!
  106 + var securityError:OSStatus = errSecSuccess
  107 +
  108 + let path: String = Bundle.main.path(forResource: "pub", ofType: "cer")!
  109 + let PKCS12Data = try! Data(contentsOf: URL(fileURLWithPath: path))
  110 + let key : NSString = kSecImportExportPassphrase as NSString
  111 + let options : NSDictionary = [key : "123456"] //客户端证书密码
  112 + //create variable for holding security information
  113 + //var privateKeyRef: SecKeyRef? = nil
  114 +
  115 + var items : CFArray?
  116 +
  117 + securityError = SecPKCS12Import(PKCS12Data as CFData, options, &items)
  118 +
  119 + if securityError == errSecSuccess {
  120 + let certItems:CFArray = items as CFArray!;
  121 + let certItemsArray:Array = certItems as Array
  122 + let dict:AnyObject? = certItemsArray.first;
  123 + if let certEntry:Dictionary = dict as? Dictionary<String, AnyObject> {
  124 + // grab the identity
  125 + let identityPointer:AnyObject? = certEntry["identity"];
  126 + let secIdentityRef:SecIdentity = identityPointer as! SecIdentity!;
  127 + // grab the trust
  128 + let trustPointer:AnyObject? = certEntry["trust"];
  129 + let trustRef:SecTrust = trustPointer as! SecTrust;
  130 + // grab the cert
  131 + let chainPointer:AnyObject? = certEntry["chain"];
  132 + identityAndTrust = IdentityAndTrust(identityRef: secIdentityRef,
  133 + trust: trustRef, certArray: chainPointer!);
  134 + }
  135 + }
  136 + return identityAndTrust;
  137 + }
  138 +}
32 139  
  140 +//定义一个结构体,存储认证相关信息
  141 +struct IdentityAndTrust {
  142 + var identityRef:SecIdentity
  143 + var trust:SecTrust
  144 + var certArray:AnyObject
33 145 }
... ...
ParentAssistant/ParentAssistant/Classes/controllers/report/ReportViewController.swift
... ... @@ -34,7 +34,8 @@ class ReportViewController: UIViewController {
34 34 imageV.contentMode = UIViewContentMode.scaleAspectFit
35 35 EmptyView.addSubview(imageV)
36 36 self.view.addSubview(EmptyView)
37   -
  37 + let backImage = UIImage(named: "navigationBar_backgrounImage")
  38 + self.navigationController?.navigationBar.setBackgroundImage(backImage, for: UIBarMetrics.default)
38 39 if self.EmptyView.isHidden {
39 40 //设置顶部按钮
40 41 setupNavigationBar()
... ... @@ -44,14 +45,8 @@ class ReportViewController: UIViewController {
44 45 }
45 46 // MARK: - 设置顶部按钮
46 47 func setupNavigationBar(){
47   - self.navigationController?.navigationBar.barStyle = UIBarStyle.default// UIColorFromRGB(0xC5DAFF)
48   - let backImage = UIImage(named: "navigationBar_backgrounImage")
49   - self.navigationController?.navigationBar.setBackgroundImage(backImage, for: UIBarMetrics.default)
50   -
51 48 self.configTheme()
52   -
53 49 setuptitleView()
54   -
55 50 }
56 51 func setuptitleView(){
57 52  
... ...
ParentAssistant/ParentAssistant/Supporting Files/Base.lproj/Main.storyboard
... ... @@ -527,10 +527,10 @@
527 527 </objects>
528 528 <point key="canvasLocation" x="54" y="117"/>
529 529 </scene>
530   - <!--Report View Controller-->
  530 + <!--报告-->
531 531 <scene sceneID="YFU-9r-YrN">
532 532 <objects>
533   - <viewController id="oqH-t7-mJp" customClass="ReportViewController" customModule="ParentAssistant" customModuleProvider="target" sceneMemberID="viewController">
  533 + <viewController title="报告" id="oqH-t7-mJp" customClass="ReportViewController" customModule="ParentAssistant" customModuleProvider="target" sceneMemberID="viewController">
534 534 <view key="view" contentMode="scaleToFill" id="5aI-3l-uAy">
535 535 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
536 536 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
... ... @@ -769,7 +769,7 @@
769 769 </constraints>
770 770 <viewLayoutGuide key="safeArea" id="9O4-jf-dgu"/>
771 771 </view>
772   - <navigationItem key="navigationItem" id="dVv-mJ-714"/>
  772 + <navigationItem key="navigationItem" title="报告" id="dVv-mJ-714"/>
773 773 <connections>
774 774 <outlet property="reportTable" destination="EEs-Ae-t7U" id="WCp-ci-zOE"/>
775 775 </connections>
... ... @@ -1991,6 +1991,9 @@
1991 1991 <navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="uLq-9a-RVg">
1992 1992 <rect key="frame" x="0.0" y="20" width="375" height="44"/>
1993 1993 <autoresizingMask key="autoresizingMask"/>
  1994 + <textAttributes key="titleTextAttributes">
  1995 + <color key="textColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
  1996 + </textAttributes>
1994 1997 </navigationBar>
1995 1998 <nil name="viewControllers"/>
1996 1999 <connections>
... ...
ParentAssistant/ParentAssistant/Supporting Files/Info.plist
... ... @@ -19,7 +19,9 @@
19 19 <key>CFBundleShortVersionString</key>
20 20 <string>1.0.0</string>
21 21 <key>CFBundleVersion</key>
22   - <string>7</string>
  22 + <string>10</string>
  23 + <key>ITSAppUsesNonExemptEncryption</key>
  24 + <false/>
23 25 <key>LSRequiresIPhoneOS</key>
24 26 <true/>
25 27 <key>NSAppTransportSecurity</key>
... ... @@ -28,11 +30,11 @@
28 30 <true/>
29 31 </dict>
30 32 <key>NSLocationWhenInUseUsageDescription</key>
31   - <string>"需要您的同意,才能在使用期间访问位置"</string>
  33 + <string>家长慧将根据您的地理位置信息,获取与位置相匹配的学校和新闻信息</string>
32 34 <key>NSMicrophoneUsageDescription</key>
33   - <string>访问麦克风</string>
  35 + <string>家长慧需要您的同意,才能访问麦克风</string>
34 36 <key>NSPhotoLibraryUsageDescription</key>
35   - <string>你可以获取本地照片</string>
  37 + <string>家长慧需要您的同意,才能访问相册</string>
36 38 <key>UILaunchStoryboardName</key>
37 39 <string>LaunchScreen</string>
38 40 <key>UIMainStoryboardFile</key>
... ...