Kaynağa Gözat

Dark Mode support, faulty URLSheme protection, bug fixes.

Hector Carrion 5 yıl önce
ebeveyn
işleme
4fa8b4c66d

+ 58
- 12
EncuestaMarle/AppDelegate.swift Dosyayı Görüntüle

@@ -13,6 +13,7 @@ import UserNotifications
13 13
 import Firebase
14 14
 import ResearchKit
15 15
 
16
+
16 17
 @UIApplicationMain
17 18
 class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
18 19
 
@@ -193,7 +194,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
193 194
         let registered = checkIfRegistered()
194 195
         
195 196
         if !registered {
196
-            let alertTitle = NSLocalizedString("Please join study first", comment: "")
197
+            let alertTitle = NSLocalizedString("Please join Tania first", comment: "")
197 198
             let alertMessage = NSLocalizedString("Press the 'Join Study' buttton below to register, then open this link again", comment: "")
198 199
             let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
199 200
             alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
@@ -210,6 +211,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
210 211
             guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
211 212
                 let params = components.queryItems else {
212 213
                     print("Invalid URL or host missing")
214
+                    
215
+                    let alertTitle = NSLocalizedString("Invalid link or resource", comment: "")
216
+                    let alertMessage = NSLocalizedString("Please contact your mentor for further assistance", comment: "")
217
+                    let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
218
+                    alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
219
+                    self.window?.rootViewController?.present(alert, animated: true, completion: nil)
220
+                    
213 221
                     return false
214 222
             }
215 223
             
@@ -219,9 +227,42 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
219 227
                 
220 228
                 registerToExperience(id: id)
221 229
                 
222
-                return true
230
+                while(newResponseID == false) {}
231
+                newResponseID = false
232
+                
233
+                if response_id == "Error:hash" {
234
+                    
235
+                    let alertTitle = NSLocalizedString("That experience does not exist", comment: "")
236
+                    let alertMessage = NSLocalizedString("Please contact your mentor for further assistance", comment: "")
237
+                    let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
238
+                    alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
239
+                    self.window?.rootViewController?.present(alert, animated: true, completion: nil)
240
+                    
241
+                    return false
242
+                }
243
+                
244
+                else if response_id == "Success" {
245
+                    
246
+                    let alertTitle = NSLocalizedString("Sucessful registration to experience", comment: "")
247
+                    let alertMessage = NSLocalizedString("Surveys will become available to answer", comment: "")
248
+                    let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
249
+                    alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
250
+                    self.window?.rootViewController?.present(alert, animated: true, completion: nil)
251
+                    
252
+                    return true
253
+                }
254
+                
255
+                return false
256
+                
223 257
             } else {
224 258
                 print("Encuesta id missing")
259
+                
260
+                let alertTitle = NSLocalizedString("Invalid link or experience ID", comment: "")
261
+                let alertMessage = NSLocalizedString("Please contact your mentor for further assistance", comment: "")
262
+                let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
263
+                alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
264
+                self.window?.rootViewController?.present(alert, animated: true, completion: nil)
265
+                
225 266
                 return false
226 267
             }
227 268
         }
@@ -256,6 +297,21 @@ extension AppDelegate: ORKPasscodeDelegate {
256 297
 }
257 298
 
258 299
 
300
+extension UIApplication {
301
+  class func topViewController(controller: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
302
+    if let tabController = controller as? UITabBarController {
303
+      return topViewController(controller: tabController.selectedViewController)
304
+    }
305
+    if let navController = controller as? UINavigationController {
306
+      return topViewController(controller: navController.visibleViewController)
307
+    }
308
+    if let presented = controller?.presentedViewController {
309
+      return topViewController(controller: presented)
310
+    }
311
+    return controller
312
+  }
313
+}
314
+
259 315
 
260 316
 func registerToExperience(id: String) {
261 317
     
@@ -298,16 +354,6 @@ func registerToExperience(id: String) {
298 354
         print ("❌ JSON Failure")
299 355
     }
300 356
     
301
-    if response_id == "Error:id_experiencia" {
302
-        
303
-        experienceAlert()
304
-        
305
-    }
306
-    
307
-    else {
308
-        
309 357
     getJsonFromUrl()
310
-        
311
-    }
312 358
     
313 359
 }

+ 38
- 0
EncuestaMarle/Assets.xcassets/white_black.colorset/Contents.json Dosyayı Görüntüle

@@ -0,0 +1,38 @@
1
+{
2
+  "info" : {
3
+    "version" : 1,
4
+    "author" : "xcode"
5
+  },
6
+  "colors" : [
7
+    {
8
+      "idiom" : "universal",
9
+      "color" : {
10
+        "color-space" : "srgb",
11
+        "components" : {
12
+          "red" : "1.000",
13
+          "alpha" : "1.000",
14
+          "blue" : "1.000",
15
+          "green" : "1.000"
16
+        }
17
+      }
18
+    },
19
+    {
20
+      "idiom" : "universal",
21
+      "appearances" : [
22
+        {
23
+          "appearance" : "luminosity",
24
+          "value" : "dark"
25
+        }
26
+      ],
27
+      "color" : {
28
+        "color-space" : "srgb",
29
+        "components" : {
30
+          "red" : "0x00",
31
+          "alpha" : "1.000",
32
+          "blue" : "0x00",
33
+          "green" : "0x00"
34
+        }
35
+      }
36
+    }
37
+  ]
38
+}

+ 38
- 0
EncuestaMarle/Assets.xcassets/white_gray.colorset/Contents.json Dosyayı Görüntüle

@@ -0,0 +1,38 @@
1
+{
2
+  "info" : {
3
+    "version" : 1,
4
+    "author" : "xcode"
5
+  },
6
+  "colors" : [
7
+    {
8
+      "idiom" : "universal",
9
+      "color" : {
10
+        "color-space" : "srgb",
11
+        "components" : {
12
+          "red" : "1.000",
13
+          "alpha" : "1.000",
14
+          "blue" : "1.000",
15
+          "green" : "1.000"
16
+        }
17
+      }
18
+    },
19
+    {
20
+      "idiom" : "universal",
21
+      "appearances" : [
22
+        {
23
+          "appearance" : "luminosity",
24
+          "value" : "dark"
25
+        }
26
+      ],
27
+      "color" : {
28
+        "color-space" : "srgb",
29
+        "components" : {
30
+          "red" : "0x38",
31
+          "alpha" : "1.000",
32
+          "blue" : "0x3B",
33
+          "green" : "0x38"
34
+        }
35
+      }
36
+    }
37
+  ]
38
+}

+ 22
- 15
EncuestaMarle/Base.lproj/Main.storyboard Dosyayı Görüntüle

@@ -4,11 +4,12 @@
4 4
     <dependencies>
5 5
         <deployment identifier="iOS"/>
6 6
         <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15510"/>
7
+        <capability name="Named colors" minToolsVersion="9.0"/>
7 8
         <capability name="Safe area layout guides" minToolsVersion="9.0"/>
8 9
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
9 10
     </dependencies>
10 11
     <scenes>
11
-        <!--Encuesta View Controller-->
12
+        <!--Survey-->
12 13
         <scene sceneID="tne-QT-ifu">
13 14
             <objects>
14 15
                 <viewController id="BYZ-38-t0r" customClass="EncuestaViewController" customModule="Tania" customModuleProvider="target" sceneMemberID="viewController">
@@ -43,7 +44,7 @@
43 44
                                 </connections>
44 45
                             </button>
45 46
                         </subviews>
46
-                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
47
+                        <color key="backgroundColor" name="white_gray"/>
47 48
                         <constraints>
48 49
                             <constraint firstItem="X5i-Gf-gnI" firstAttribute="leading" secondItem="6Tk-OE-BBY" secondAttribute="leading" constant="35" identifier="Ans2" id="FUW-5x-JJm"/>
49 50
                             <constraint firstItem="X5i-Gf-gnI" firstAttribute="top" secondItem="6Tk-OE-BBY" secondAttribute="top" constant="241" identifier="Ans3" id="Isl-Wl-ceq"/>
@@ -51,7 +52,7 @@
51 52
                         </constraints>
52 53
                         <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
53 54
                     </view>
54
-                    <navigationItem key="navigationItem" id="a31-hX-hUP"/>
55
+                    <navigationItem key="navigationItem" title="Survey" id="a31-hX-hUP"/>
55 56
                 </viewController>
56 57
                 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
57 58
             </objects>
@@ -180,7 +181,7 @@ To log-in to a previously registered account tap Recover Account above.</string>
180 181
                                 <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
181 182
                             </textView>
182 183
                         </subviews>
183
-                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
184
+                        <color key="backgroundColor" name="white_black"/>
184 185
                         <constraints>
185 186
                             <constraint firstItem="gGJ-33-J27" firstAttribute="top" secondItem="beN-qE-bp8" secondAttribute="bottom" constant="8" identifier="O3" id="4zi-tr-PYm"/>
186 187
                             <constraint firstItem="gGJ-33-J27" firstAttribute="leading" secondItem="BO1-Dh-wF9" secondAttribute="leading" constant="20" identifier="O4" id="CVA-X6-d88"/>
@@ -240,7 +241,7 @@ To log-in to a previously registered account tap Recover Account above.</string>
240 241
                     </tabBar>
241 242
                     <userDefinedRuntimeAttributes>
242 243
                         <userDefinedRuntimeAttribute type="number" keyPath="selectedIndex">
243
-                            <integer key="value" value="1"/>
244
+                            <integer key="value" value="0"/>
244 245
                         </userDefinedRuntimeAttribute>
245 246
                     </userDefinedRuntimeAttributes>
246 247
                     <connections>
@@ -256,7 +257,7 @@ To log-in to a previously registered account tap Recover Account above.</string>
256 257
         <scene sceneID="VzZ-Qy-O7s">
257 258
             <objects>
258 259
                 <navigationController automaticallyAdjustsScrollViewInsets="NO" id="6cF-m5-fPN" sceneMemberID="viewController">
259
-                    <tabBarItem key="tabBarItem" title="Survey" image="tab_activities" id="yyT-tP-N6f"/>
260
+                    <tabBarItem key="tabBarItem" title="Survey" image="pencil" catalog="system" id="yyT-tP-N6f"/>
260 261
                     <toolbarItems/>
261 262
                     <navigationBar key="navigationBar" contentMode="scaleToFill" id="Kt2-3G-lKB">
262 263
                         <rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
@@ -311,13 +312,13 @@ To log-in to a previously registered account tap Recover Account above.</string>
311 312
                     <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="49" sectionHeaderHeight="28" sectionFooterHeight="28" id="MXz-QS-IlS">
312 313
                         <rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
313 314
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
314
-                        <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
315
+                        <color key="backgroundColor" name="white_gray"/>
315 316
                         <view key="tableHeaderView" contentMode="scaleToFill" id="UPL-u9-fkL" customClass="ProfileHeaderView" customModule="Tania" customModuleProvider="target">
316 317
                             <rect key="frame" x="0.0" y="0.0" width="414" height="621"/>
317 318
                             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
318 319
                             <subviews>
319
-                                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Currently Participating In MARLE" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.80000001192092896" translatesAutoresizingMaskIntoConstraints="NO" id="nI8-Mq-6Bk">
320
-                                    <rect key="frame" x="8" y="16" width="398" height="20.666666666666671"/>
320
+                                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="251" text="Currently Participating In Tania" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.80000001192092896" translatesAutoresizingMaskIntoConstraints="NO" id="nI8-Mq-6Bk">
321
+                                    <rect key="frame" x="8" y="16" width="398" height="21"/>
321 322
                                     <fontDescription key="fontDescription" type="system" pointSize="17"/>
322 323
                                     <nil key="highlightedColor"/>
323 324
                                 </label>
@@ -329,7 +330,7 @@ To log-in to a previously registered account tap Recover Account above.</string>
329 330
                                     <nil key="highlightedColor"/>
330 331
                                 </label>
331 332
                                 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="We0-cd-h10">
332
-                                    <rect key="frame" x="8" y="88.333333333333329" width="398" height="21"/>
333
+                                    <rect key="frame" x="8" y="88.666666666666671" width="398" height="21"/>
333 334
                                     <fontDescription key="fontDescription" type="system" weight="semibold" pointSize="17"/>
334 335
                                     <inset key="contentEdgeInsets" minX="7" minY="0.0" maxX="0.0" maxY="0.0"/>
335 336
                                     <state key="normal" title="See your Consent Form">
@@ -340,7 +341,7 @@ To log-in to a previously registered account tap Recover Account above.</string>
340 341
                                     </connections>
341 342
                                 </button>
342 343
                                 <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="leading" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="wordWrap" translatesAutoresizingMaskIntoConstraints="NO" id="wkQ-h0-GIO">
343
-                                    <rect key="frame" x="8" y="117.33333333333331" width="398" height="41"/>
344
+                                    <rect key="frame" x="8" y="117.66666666666669" width="398" height="41"/>
344 345
                                     <fontDescription key="fontDescription" type="system" weight="semibold" pointSize="17"/>
345 346
                                     <inset key="contentEdgeInsets" minX="10" minY="10" maxX="10" maxY="10"/>
346 347
                                     <state key="normal" title="Leave Study">
@@ -352,7 +353,7 @@ To log-in to a previously registered account tap Recover Account above.</string>
352 353
                                     </connections>
353 354
                                 </button>
354 355
                             </subviews>
355
-                            <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
356
+                            <color key="backgroundColor" name="white_gray"/>
356 357
                             <constraints>
357 358
                                 <constraint firstItem="We0-cd-h10" firstAttribute="top" secondItem="nI8-Mq-6Bk" secondAttribute="bottom" constant="51.670000000000002" identifier="S4" id="E85-iU-xtF"/>
358 359
                                 <constraint firstAttribute="trailing" secondItem="We0-cd-h10" secondAttribute="trailing" constant="8" identifier="S5" id="KP5-kT-u4x"/>
@@ -392,7 +393,7 @@ To log-in to a previously registered account tap Recover Account above.</string>
392 393
         <scene sceneID="Hxl-vA-dRR">
393 394
             <objects>
394 395
                 <navigationController automaticallyAdjustsScrollViewInsets="NO" id="IbW-FC-OA0" sceneMemberID="viewController">
395
-                    <tabBarItem key="tabBarItem" title="Settings" image="tab_profile" id="04I-wD-Xhf"/>
396
+                    <tabBarItem key="tabBarItem" title="Settings" image="gear" catalog="system" id="04I-wD-Xhf"/>
396 397
                     <toolbarItems/>
397 398
                     <navigationBar key="navigationBar" contentMode="scaleToFill" id="0S4-Xx-Xnh">
398 399
                         <rect key="frame" x="0.0" y="0.0" width="414" height="44"/>
@@ -409,7 +410,13 @@ To log-in to a previously registered account tap Recover Account above.</string>
409 410
         </scene>
410 411
     </scenes>
411 412
     <resources>
412
-        <image name="tab_activities" width="16" height="16"/>
413
-        <image name="tab_profile" width="16" height="16"/>
413
+        <image name="gear" catalog="system" width="64" height="58"/>
414
+        <image name="pencil" catalog="system" width="64" height="56"/>
415
+        <namedColor name="white_black">
416
+            <color red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
417
+        </namedColor>
418
+        <namedColor name="white_gray">
419
+            <color red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
420
+        </namedColor>
414 421
     </resources>
415 422
 </document>

+ 11
- 1
EncuestaMarle/EncuestaViewController.swift Dosyayı Görüntüle

@@ -26,6 +26,15 @@ var jsonDict = [String: Any]()
26 26
 var n_jsonDict = [String: Any]()
27 27
 var response_survey = String()
28 28
 
29
+var newResponseID: Bool = false
30
+
31
+var response_id: String = "" {
32
+    didSet {
33
+        newResponseID = true
34
+    }
35
+}
36
+
37
+
29 38
 func getJsonFromUrl(){
30 39
     print("entre a getJsonFromUrl ⚠️")
31 40
     let request = NSMutableURLRequest(url: NSURL(string: "http://tania.uprrp.edu/getSubQ2.php?tk="+token)! as URL, cachePolicy: .reloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 60)
@@ -221,7 +230,7 @@ class EncuestaViewController: UIViewController {
221 230
         //semaphore.wait()
222 231
         if response_survey == "Error:NoHay"{
223 232
             let alertTitle = NSLocalizedString("No Survey", comment: "")
224
-            let alertMessage = NSLocalizedString("There is no survey available right now. Please check later.", comment: "")
233
+            let alertMessage = NSLocalizedString("There is no survey available right now. Please register to an experience or check back later.", comment: "")
225 234
             let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
226 235
             alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
227 236
             self.present(alert, animated: true, completion: nil)
@@ -243,6 +252,7 @@ class EncuestaViewController: UIViewController {
243 252
 
244 253
     }
245 254
     
255
+    
246 256
     //override func didwake
247 257
 }
248 258
 

+ 15
- 3
EncuestaMarle/OnboardingViewController.swift Dosyayı Görüntüle

@@ -43,8 +43,6 @@ var jsonDict_reset = [String: Any]()
43 43
 var n_jsonDict_reset = [String: Any]()
44 44
 var response_reset = String()
45 45
 
46
-var response_id = String()
47
-
48 46
 func getConsent_task(task: ORKTaskViewController) -> ORKTaskViewController{
49 47
     return task
50 48
 }
@@ -431,6 +429,9 @@ extension OnboardingViewController : ORKTaskViewControllerDelegate {
431 429
                 else {
432 430
                     UserDefaults.standard.set(true, forKey: "registered")
433 431
                     UserDefaults.standard.synchronize()
432
+                    
433
+                    // MARK: Restore PDF here
434
+                    
434 435
                     performSegue(withIdentifier: "unwindToStudy", sender: nil)
435 436
                 }
436 437
             }
@@ -454,7 +455,7 @@ extension OnboardingViewController : ORKTaskViewControllerDelegate {
454 455
                         
455 456
                         do {
456 457
                             try data?.write(to:docURL! as URL)
457
-                            print("PDF generated ✅")
458
+                            print("PDF written to disk ✅")
458 459
                             print(docURL! as URL)
459 460
                             if let pdfBase64 = data?.base64EncodedString() {
460 461
                                 sendPDF(pdfBase64, signatureDate)
@@ -575,3 +576,14 @@ extension OnboardingViewController : ORKTaskViewControllerDelegate {
575 576
 //        return "id: \(id), constant: \(constant)" //you may print whatever you want here
576 577
 //    }
577 578
 //}
579
+
580
+extension ORKTaskViewController {
581
+    
582
+    override open func viewDidLoad() {
583
+        super.viewDidLoad()
584
+        if #available(iOS 13, *) {
585
+            overrideUserInterfaceStyle = .light
586
+        }
587
+    }
588
+    
589
+}

+ 3
- 0
EncuestaMarle/ResearchContainerViewController.swift Dosyayı Görüntüle

@@ -119,6 +119,9 @@ extension ResearchContainerViewController: ORKTaskViewControllerDelegate {
119 119
                 print("❌ User is withdrawing with string: ")
120 120
                 print(jsonString_withdraw)
121 121
                 sendJson_withdraw()
122
+                
123
+                UserDefaults.standard.set(false, forKey: "registered")
124
+                UserDefaults.standard.synchronize()
122 125
             }
123 126
             dismiss(animated: true, completion: nil)
124 127
         }