Browse Source

Support for inscription via URL Scheme including registered and experience existence checks and alerts.

Hector Carrion 5 years ago
parent
commit
5a82182134

+ 93
- 0
EncuestaMarle/AppDelegate.swift View File

186
         return container
186
         return container
187
     }()
187
     }()
188
     
188
     
189
+    // MARK: - URL Scheme Support
189
     
190
     
191
+    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
192
+        
193
+        let registered = checkIfRegistered()
194
+        
195
+        if !registered {
196
+            let alertTitle = NSLocalizedString("Please join study first", comment: "")
197
+            let alertMessage = NSLocalizedString("Press the 'Join Study' buttton below to register, then open this link again", comment: "")
198
+            let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertController.Style.alert)
199
+            alert.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler: nil))
200
+            self.window?.rootViewController?.present(alert, animated: true, completion: nil)
201
+            
202
+            return false
203
+        }
204
+        
205
+        else {
206
+            
207
+            let host = url.host
208
+            
209
+            // Process the URL.
210
+            guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
211
+                let params = components.queryItems else {
212
+                    print("Invalid URL or host missing")
213
+                    return false
214
+            }
215
+            
216
+            if let id = params.first(where: { $0.name == "id" })?.value {
217
+                print("Host = \(host ?? "Error: No host in URL")")
218
+                print("Registrating user to experience ID = \(id)")
219
+                
220
+                registerToExperience(id: id)
221
+                
222
+                return true
223
+            } else {
224
+                print("Encuesta id missing")
225
+                return false
226
+            }
227
+        }
228
+    }
190
 
229
 
191
     // MARK: - Core Data Saving support
230
     // MARK: - Core Data Saving support
192
 
231
 
218
 
257
 
219
 
258
 
220
 
259
 
260
+func registerToExperience(id: String) {
261
+    
262
+    let jsonObject: NSMutableDictionary = NSMutableDictionary()
263
+    
264
+    jsonObject.setValue(token, forKey: "token")
265
+    jsonObject.setValue(id, forKey: "id_experiencia")
266
+    
267
+    let request = NSMutableURLRequest(url: NSURL(string: "http://tania.uprrp.edu/inscripcionExperiencia.php")! as URL)
268
+    request.httpMethod = "POST"
269
+    
270
+    let jsonData: NSData
271
+            
272
+    do {
273
+        jsonData = try JSONSerialization.data(withJSONObject: jsonObject, options: JSONSerialization.WritingOptions()) as NSData
274
+        let jsonID = NSString(data: jsonData as Data, encoding: String.Encoding.utf8.rawValue) as! String
275
+        print("✅ ID recieved, sending request...")
276
+        
277
+        let postString = "data=\(jsonID)"
278
+        request.httpBody = postString.data(using: String.Encoding.utf8)
279
+        
280
+        let task = URLSession.shared.dataTask(with: request as URLRequest) {
281
+            data, response, error in
282
+            if error != nil {
283
+                print("error=\(String(describing: error))")
284
+                return
285
+            }
286
+            
287
+            print("response solito ID = \(String(describing: response))") //Error: 1062
288
+            
289
+            let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
290
+            print("responseString ID = \(String(describing: responseString))")
291
+            
292
+            response_id = responseString as! String
293
+        }
294
+        
295
+        task.resume()
296
+        
297
+    } catch {
298
+        print ("❌ JSON Failure")
299
+    }
300
+    
301
+    if response_id == "Error:id_experiencia" {
302
+        
303
+        experienceAlert()
304
+        
305
+    }
306
+    
307
+    else {
308
+        
309
+    getJsonFromUrl()
310
+        
311
+    }
312
+    
313
+}

+ 1
- 1
EncuestaMarle/Info.plist View File

25
 			<string>MARLEApp.EncuestaMarle-h</string>
25
 			<string>MARLEApp.EncuestaMarle-h</string>
26
 			<key>CFBundleURLSchemes</key>
26
 			<key>CFBundleURLSchemes</key>
27
 			<array>
27
 			<array>
28
-				<string>marle</string>
28
+				<string>tania</string>
29
 			</array>
29
 			</array>
30
 		</dict>
30
 		</dict>
31
 	</array>
31
 	</array>

+ 2
- 0
EncuestaMarle/OnboardingViewController.swift View File

43
 var n_jsonDict_reset = [String: Any]()
43
 var n_jsonDict_reset = [String: Any]()
44
 var response_reset = String()
44
 var response_reset = String()
45
 
45
 
46
+var response_id = String()
47
+
46
 func getConsent_task(task: ORKTaskViewController) -> ORKTaskViewController{
48
 func getConsent_task(task: ORKTaskViewController) -> ORKTaskViewController{
47
     return task
49
     return task
48
 }
50
 }

+ 2
- 2
EncuestaMarle/ResearchContainerViewController.swift View File

51
 
51
 
52
 }
52
 }
53
 
53
 
54
-func checkIfRegister() -> Bool
54
+func checkIfRegistered() -> Bool
55
 {
55
 {
56
     //
56
     //
57
     // Getting
57
     // Getting
78
     override func viewDidLoad() {
78
     override func viewDidLoad() {
79
         super.viewDidLoad()
79
         super.viewDidLoad()
80
         
80
         
81
-        let registered = checkIfRegister()
81
+        let registered = checkIfRegistered()
82
         //if response_token == true {
82
         //if response_token == true {
83
         if registered == true {
83
         if registered == true {
84
             print("$$$$$$$Esta registrada$$$$$$$$$")
84
             print("$$$$$$$Esta registrada$$$$$$$$$")

+ 19
- 19
Tania.xcodeproj/project.pbxproj View File

9
 /* Begin PBXBuildFile section */
9
 /* Begin PBXBuildFile section */
10
 		23C456DB2270BAEF008CC76B /* ORKESerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 23C456D92270BAEE008CC76B /* ORKESerialization.m */; };
10
 		23C456DB2270BAEF008CC76B /* ORKESerialization.m in Sources */ = {isa = PBXBuildFile; fileRef = 23C456D92270BAEE008CC76B /* ORKESerialization.m */; };
11
 		23C570622271EF80000C7E90 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = 23C570612271EF80000C7E90 /* Podfile */; };
11
 		23C570622271EF80000C7E90 /* Podfile in Resources */ = {isa = PBXBuildFile; fileRef = 23C570612271EF80000C7E90 /* Podfile */; };
12
-		35439533237E182A00E73402 /* ResearchKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 35439530237E181E00E73402 /* ResearchKit.framework */; };
13
-		35439534237E182A00E73402 /* ResearchKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 35439530237E181E00E73402 /* ResearchKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
14
 		35602D5E237E1D2D008C9338 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 35602D5D237E1D2D008C9338 /* LaunchScreen.xib */; };
12
 		35602D5E237E1D2D008C9338 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 35602D5D237E1D2D008C9338 /* LaunchScreen.xib */; };
13
+		357D804B237F19B0002403F2 /* ResearchKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 357D8048237F199D002403F2 /* ResearchKit.framework */; };
14
+		357D804C237F19B0002403F2 /* ResearchKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 357D8048237F199D002403F2 /* ResearchKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
15
 		371DA37622621B03006C22EC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371DA37522621B03006C22EC /* AppDelegate.swift */; };
15
 		371DA37622621B03006C22EC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371DA37522621B03006C22EC /* AppDelegate.swift */; };
16
 		371DA37822621B03006C22EC /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371DA37722621B03006C22EC /* ViewController.swift */; };
16
 		371DA37822621B03006C22EC /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 371DA37722621B03006C22EC /* ViewController.swift */; };
17
 		371DA37B22621B03006C22EC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 371DA37922621B03006C22EC /* Main.storyboard */; };
17
 		371DA37B22621B03006C22EC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 371DA37922621B03006C22EC /* Main.storyboard */; };
33
 /* End PBXBuildFile section */
33
 /* End PBXBuildFile section */
34
 
34
 
35
 /* Begin PBXContainerItemProxy section */
35
 /* Begin PBXContainerItemProxy section */
36
-		3543952F237E181E00E73402 /* PBXContainerItemProxy */ = {
36
+		357D8047237F199D002403F2 /* PBXContainerItemProxy */ = {
37
 			isa = PBXContainerItemProxy;
37
 			isa = PBXContainerItemProxy;
38
-			containerPortal = 35439529237E181600E73402 /* ResearchKit.xcodeproj */;
38
+			containerPortal = 357D8041237F199B002403F2 /* ResearchKit.xcodeproj */;
39
 			proxyType = 2;
39
 			proxyType = 2;
40
 			remoteGlobalIDString = B183A5951A8535D100C76870;
40
 			remoteGlobalIDString = B183A5951A8535D100C76870;
41
 			remoteInfo = ResearchKit;
41
 			remoteInfo = ResearchKit;
42
 		};
42
 		};
43
-		35439531237E181E00E73402 /* PBXContainerItemProxy */ = {
43
+		357D8049237F199D002403F2 /* PBXContainerItemProxy */ = {
44
 			isa = PBXContainerItemProxy;
44
 			isa = PBXContainerItemProxy;
45
-			containerPortal = 35439529237E181600E73402 /* ResearchKit.xcodeproj */;
45
+			containerPortal = 357D8041237F199B002403F2 /* ResearchKit.xcodeproj */;
46
 			proxyType = 2;
46
 			proxyType = 2;
47
 			remoteGlobalIDString = 86CC8E9A1AC09332001CCD89;
47
 			remoteGlobalIDString = 86CC8E9A1AC09332001CCD89;
48
 			remoteInfo = ResearchKitTests;
48
 			remoteInfo = ResearchKitTests;
70
 			dstPath = "";
70
 			dstPath = "";
71
 			dstSubfolderSpec = 10;
71
 			dstSubfolderSpec = 10;
72
 			files = (
72
 			files = (
73
-				35439534237E182A00E73402 /* ResearchKit.framework in Embed Frameworks */,
73
+				357D804C237F19B0002403F2 /* ResearchKit.framework in Embed Frameworks */,
74
 			);
74
 			);
75
 			name = "Embed Frameworks";
75
 			name = "Embed Frameworks";
76
 			runOnlyForDeploymentPostprocessing = 0;
76
 			runOnlyForDeploymentPostprocessing = 0;
81
 		23C456D92270BAEE008CC76B /* ORKESerialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORKESerialization.m; sourceTree = "<group>"; };
81
 		23C456D92270BAEE008CC76B /* ORKESerialization.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ORKESerialization.m; sourceTree = "<group>"; };
82
 		23C456DA2270BAEF008CC76B /* ORKESerialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ORKESerialization.h; sourceTree = "<group>"; };
82
 		23C456DA2270BAEF008CC76B /* ORKESerialization.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ORKESerialization.h; sourceTree = "<group>"; };
83
 		23C570612271EF80000C7E90 /* Podfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Podfile; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
83
 		23C570612271EF80000C7E90 /* Podfile */ = {isa = PBXFileReference; lastKnownFileType = text; path = Podfile; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
84
-		35439529237E181600E73402 /* ResearchKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ResearchKit.xcodeproj; path = "../ResearchKit-master/ResearchKit.xcodeproj"; sourceTree = "<group>"; };
85
 		35602D5D237E1D2D008C9338 /* LaunchScreen.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LaunchScreen.xib; sourceTree = "<group>"; };
84
 		35602D5D237E1D2D008C9338 /* LaunchScreen.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LaunchScreen.xib; sourceTree = "<group>"; };
85
+		357D8041237F199B002403F2 /* ResearchKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ResearchKit.xcodeproj; path = "../ResearchKit-master/ResearchKit.xcodeproj"; sourceTree = "<group>"; };
86
 		371DA37222621B03006C22EC /* Tania.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tania.app; sourceTree = BUILT_PRODUCTS_DIR; };
86
 		371DA37222621B03006C22EC /* Tania.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Tania.app; sourceTree = BUILT_PRODUCTS_DIR; };
87
 		371DA37522621B03006C22EC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
87
 		371DA37522621B03006C22EC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
88
 		371DA37722621B03006C22EC /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
88
 		371DA37722621B03006C22EC /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
118
 			isa = PBXFrameworksBuildPhase;
118
 			isa = PBXFrameworksBuildPhase;
119
 			buildActionMask = 2147483647;
119
 			buildActionMask = 2147483647;
120
 			files = (
120
 			files = (
121
-				35439533237E182A00E73402 /* ResearchKit.framework in Frameworks */,
121
+				357D804B237F19B0002403F2 /* ResearchKit.framework in Frameworks */,
122
 				FEDC90410884E4DA2C2B09A8 /* Pods_EncuestaMarle.framework in Frameworks */,
122
 				FEDC90410884E4DA2C2B09A8 /* Pods_EncuestaMarle.framework in Frameworks */,
123
 			);
123
 			);
124
 			runOnlyForDeploymentPostprocessing = 0;
124
 			runOnlyForDeploymentPostprocessing = 0;
148
 			name = Frameworks;
148
 			name = Frameworks;
149
 			sourceTree = "<group>";
149
 			sourceTree = "<group>";
150
 		};
150
 		};
151
-		3543952A237E181600E73402 /* Products */ = {
151
+		357D8042237F199B002403F2 /* Products */ = {
152
 			isa = PBXGroup;
152
 			isa = PBXGroup;
153
 			children = (
153
 			children = (
154
-				35439530237E181E00E73402 /* ResearchKit.framework */,
155
-				35439532237E181E00E73402 /* ResearchKitTests.xctest */,
154
+				357D8048237F199D002403F2 /* ResearchKit.framework */,
155
+				357D804A237F199D002403F2 /* ResearchKitTests.xctest */,
156
 			);
156
 			);
157
 			name = Products;
157
 			name = Products;
158
 			sourceTree = "<group>";
158
 			sourceTree = "<group>";
160
 		371DA36922621B03006C22EC = {
160
 		371DA36922621B03006C22EC = {
161
 			isa = PBXGroup;
161
 			isa = PBXGroup;
162
 			children = (
162
 			children = (
163
-				35439529237E181600E73402 /* ResearchKit.xcodeproj */,
163
+				357D8041237F199B002403F2 /* ResearchKit.xcodeproj */,
164
 				23C570612271EF80000C7E90 /* Podfile */,
164
 				23C570612271EF80000C7E90 /* Podfile */,
165
 				371DA37422621B03006C22EC /* EncuestaMarle */,
165
 				371DA37422621B03006C22EC /* EncuestaMarle */,
166
 				371DA38C22621B06006C22EC /* EncuestaMarleTests */,
166
 				371DA38C22621B06006C22EC /* EncuestaMarleTests */,
340
 			projectDirPath = "";
340
 			projectDirPath = "";
341
 			projectReferences = (
341
 			projectReferences = (
342
 				{
342
 				{
343
-					ProductGroup = 3543952A237E181600E73402 /* Products */;
344
-					ProjectRef = 35439529237E181600E73402 /* ResearchKit.xcodeproj */;
343
+					ProductGroup = 357D8042237F199B002403F2 /* Products */;
344
+					ProjectRef = 357D8041237F199B002403F2 /* ResearchKit.xcodeproj */;
345
 				},
345
 				},
346
 			);
346
 			);
347
 			projectRoot = "";
347
 			projectRoot = "";
354
 /* End PBXProject section */
354
 /* End PBXProject section */
355
 
355
 
356
 /* Begin PBXReferenceProxy section */
356
 /* Begin PBXReferenceProxy section */
357
-		35439530237E181E00E73402 /* ResearchKit.framework */ = {
357
+		357D8048237F199D002403F2 /* ResearchKit.framework */ = {
358
 			isa = PBXReferenceProxy;
358
 			isa = PBXReferenceProxy;
359
 			fileType = wrapper.framework;
359
 			fileType = wrapper.framework;
360
 			path = ResearchKit.framework;
360
 			path = ResearchKit.framework;
361
-			remoteRef = 3543952F237E181E00E73402 /* PBXContainerItemProxy */;
361
+			remoteRef = 357D8047237F199D002403F2 /* PBXContainerItemProxy */;
362
 			sourceTree = BUILT_PRODUCTS_DIR;
362
 			sourceTree = BUILT_PRODUCTS_DIR;
363
 		};
363
 		};
364
-		35439532237E181E00E73402 /* ResearchKitTests.xctest */ = {
364
+		357D804A237F199D002403F2 /* ResearchKitTests.xctest */ = {
365
 			isa = PBXReferenceProxy;
365
 			isa = PBXReferenceProxy;
366
 			fileType = wrapper.cfbundle;
366
 			fileType = wrapper.cfbundle;
367
 			path = ResearchKitTests.xctest;
367
 			path = ResearchKitTests.xctest;
368
-			remoteRef = 35439531237E181E00E73402 /* PBXContainerItemProxy */;
368
+			remoteRef = 357D8049237F199D002403F2 /* PBXContainerItemProxy */;
369
 			sourceTree = BUILT_PRODUCTS_DIR;
369
 			sourceTree = BUILT_PRODUCTS_DIR;
370
 		};
370
 		};
371
 /* End PBXReferenceProxy section */
371
 /* End PBXReferenceProxy section */