Added SDK initialization checks, Safe unwrapping, Error Logging and isSDKInitialized method
Showing
4 changed files
with
123 additions
and
40 deletions
| ... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
| 7 | <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> | 7 | <key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key> |
| 8 | <dict> | 8 | <dict> |
| 9 | <key>orderHint</key> | 9 | <key>orderHint</key> |
| 10 | - <integer>0</integer> | 10 | + <integer>1</integer> |
| 11 | </dict> | 11 | </dict> |
| 12 | </dict> | 12 | </dict> |
| 13 | </dict> | 13 | </dict> | ... | ... |
| ... | @@ -7,7 +7,7 @@ | ... | @@ -7,7 +7,7 @@ |
| 7 | <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> | 7 | <key>SwiftWarplyFramework.xcscheme_^#shared#^_</key> |
| 8 | <dict> | 8 | <dict> |
| 9 | <key>orderHint</key> | 9 | <key>orderHint</key> |
| 10 | - <integer>1</integer> | 10 | + <integer>0</integer> |
| 11 | </dict> | 11 | </dict> |
| 12 | </dict> | 12 | </dict> |
| 13 | </dict> | 13 | </dict> | ... | ... |
No preview for this file type
| ... | @@ -2116,14 +2116,14 @@ public class swiftApi { | ... | @@ -2116,14 +2116,14 @@ public class swiftApi { |
| 2116 | let instanceOfMyApi = MyApi() | 2116 | let instanceOfMyApi = MyApi() |
| 2117 | let campaignInfo = instanceOfMyApi.provideInfoForCampaign() | 2117 | let campaignInfo = instanceOfMyApi.provideInfoForCampaign() |
| 2118 | let finalUrl = (campaign.index_url ?? "") | 2118 | let finalUrl = (campaign.index_url ?? "") |
| 2119 | - // + "?web_id=" + (campaignInfo?["web_id"] as! String) | 2119 | + // + "?web_id=" + (campaignInfo?["web_id"] as? String ?? "") |
| 2120 | - // + "&app_uuid=" + (campaignInfo?["app_uuid"] as! String) | 2120 | + // + "&app_uuid=" + (campaignInfo?["app_uuid"] as? String ?? "") |
| 2121 | - // + "&api_key=" + (campaignInfo?["api_key"] as! String) | 2121 | + // + "&api_key=" + (campaignInfo?["api_key"] as? String ?? "") |
| 2122 | // + "&session_uuid=" + (campaign.session_uuid ?? "") | 2122 | // + "&session_uuid=" + (campaign.session_uuid ?? "") |
| 2123 | - // + "&access_token=" + (campaignInfo?["access_token"] as! String) | 2123 | + // + "&access_token=" + (campaignInfo?["access_token"] as? String ?? "") |
| 2124 | - // + "&refresh_token=" + (campaignInfo?["refresh_token"] as! String) | 2124 | + // + "&refresh_token=" + (campaignInfo?["refresh_token"] as? String ?? "") |
| 2125 | - // + "&client_id=" + (campaignInfo?["client_id"] as! String) | 2125 | + // + "&client_id=" + (campaignInfo?["client_id"] as? String ?? "") |
| 2126 | - // + "&client_secret=" + (campaignInfo?["client_secret"] as! String); | 2126 | + // + "&client_secret=" + (campaignInfo?["client_secret"] as? String ?? ""); |
| 2127 | 2127 | ||
| 2128 | print("constructCampaignUrl url: " + finalUrl) | 2128 | print("constructCampaignUrl url: " + finalUrl) |
| 2129 | return finalUrl | 2129 | return finalUrl |
| ... | @@ -2251,25 +2251,37 @@ public class swiftApi { | ... | @@ -2251,25 +2251,37 @@ public class swiftApi { |
| 2251 | let campaignInfo = instanceOfMyApi.provideInfoForCampaign() | 2251 | let campaignInfo = instanceOfMyApi.provideInfoForCampaign() |
| 2252 | 2252 | ||
| 2253 | let jsonObject: [String: String] = [ | 2253 | let jsonObject: [String: String] = [ |
| 2254 | - "web_id": (campaignInfo?["web_id"] as! String), | 2254 | + "web_id": (campaignInfo?["web_id"] as? String ?? ""), |
| 2255 | - "app_uuid": (campaignInfo?["app_uuid"] as! String), | 2255 | + "app_uuid": (campaignInfo?["app_uuid"] as? String ?? ""), |
| 2256 | - "api_key": (campaignInfo?["api_key"] as! String), | 2256 | + "api_key": (campaignInfo?["api_key"] as? String ?? ""), |
| 2257 | "session_uuid": (campaign.session_uuid ?? ""), | 2257 | "session_uuid": (campaign.session_uuid ?? ""), |
| 2258 | - "access_token": (campaignInfo?["access_token"] as! String), | 2258 | + "access_token": (campaignInfo?["access_token"] as? String ?? ""), |
| 2259 | - "refresh_token": (campaignInfo?["refresh_token"] as! String), | 2259 | + "refresh_token": (campaignInfo?["refresh_token"] as? String ?? ""), |
| 2260 | - "client_id": (campaignInfo?["client_id"] as! String), | 2260 | + "client_id": (campaignInfo?["client_id"] as? String ?? ""), |
| 2261 | - "client_secret": (campaignInfo?["client_secret"] as! String), | 2261 | + "client_secret": (campaignInfo?["client_secret"] as? String ?? ""), |
| 2262 | "lan": swiftApi().getApplicationLocale(), | 2262 | "lan": swiftApi().getApplicationLocale(), |
| 2263 | "dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false") | 2263 | "dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false") |
| 2264 | ] | 2264 | ] |
| 2265 | 2265 | ||
| 2266 | + // let encoder = JSONEncoder() | ||
| 2267 | + // encoder.outputFormatting = .prettyPrinted | ||
| 2268 | + // let data = try! encoder.encode(jsonObject) | ||
| 2269 | + // let stringData = String(data: data, encoding: .utf8) ?? "" | ||
| 2270 | + | ||
| 2271 | + // print("constructCampaignParams: " + stringData) | ||
| 2272 | + // return stringData | ||
| 2273 | + | ||
| 2274 | + do { | ||
| 2266 | let encoder = JSONEncoder() | 2275 | let encoder = JSONEncoder() |
| 2267 | encoder.outputFormatting = .prettyPrinted | 2276 | encoder.outputFormatting = .prettyPrinted |
| 2268 | - let data = try! encoder.encode(jsonObject) | 2277 | + let data = try encoder.encode(jsonObject) |
| 2269 | let stringData = String(data: data, encoding: .utf8) ?? "" | 2278 | let stringData = String(data: data, encoding: .utf8) ?? "" |
| 2270 | - | ||
| 2271 | print("constructCampaignParams: " + stringData) | 2279 | print("constructCampaignParams: " + stringData) |
| 2272 | return stringData | 2280 | return stringData |
| 2281 | + } catch { | ||
| 2282 | + print("Error encoding campaign params: \(error)") | ||
| 2283 | + return "{}" | ||
| 2284 | + } | ||
| 2273 | 2285 | ||
| 2274 | // do { | 2286 | // do { |
| 2275 | // let data = try JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted) | 2287 | // let data = try JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted) |
| ... | @@ -2289,26 +2301,38 @@ public class swiftApi { | ... | @@ -2289,26 +2301,38 @@ public class swiftApi { |
| 2289 | let campaignInfo = instanceOfMyApi.provideInfoForCampaign() | 2301 | let campaignInfo = instanceOfMyApi.provideInfoForCampaign() |
| 2290 | 2302 | ||
| 2291 | let jsonObject: [String: String] = [ | 2303 | let jsonObject: [String: String] = [ |
| 2292 | - "web_id": (campaignInfo?["web_id"] as! String), | 2304 | + "web_id": (campaignInfo?["web_id"] as? String ?? ""), |
| 2293 | - "app_uuid": (campaignInfo?["app_uuid"] as! String), | 2305 | + "app_uuid": (campaignInfo?["app_uuid"] as? String ?? ""), |
| 2294 | - "api_key": (campaignInfo?["api_key"] as! String), | 2306 | + "api_key": (campaignInfo?["api_key"] as? String ?? ""), |
| 2295 | "session_uuid": (campaign.session_uuid ?? ""), | 2307 | "session_uuid": (campaign.session_uuid ?? ""), |
| 2296 | - "access_token": (campaignInfo?["access_token"] as! String), | 2308 | + "access_token": (campaignInfo?["access_token"] as? String ?? ""), |
| 2297 | - "refresh_token": (campaignInfo?["refresh_token"] as! String), | 2309 | + "refresh_token": (campaignInfo?["refresh_token"] as? String ?? ""), |
| 2298 | - "client_id": (campaignInfo?["client_id"] as! String), | 2310 | + "client_id": (campaignInfo?["client_id"] as? String ?? ""), |
| 2299 | - "client_secret": (campaignInfo?["client_secret"] as! String), | 2311 | + "client_secret": (campaignInfo?["client_secret"] as? String ?? ""), |
| 2300 | "map": (isMap ? "true" : "false"), | 2312 | "map": (isMap ? "true" : "false"), |
| 2301 | "lan": swiftApi().getApplicationLocale(), | 2313 | "lan": swiftApi().getApplicationLocale(), |
| 2302 | "dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false") | 2314 | "dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false") |
| 2303 | ] | 2315 | ] |
| 2304 | 2316 | ||
| 2317 | + // let encoder = JSONEncoder() | ||
| 2318 | + // encoder.outputFormatting = .prettyPrinted | ||
| 2319 | + // let data = try! encoder.encode(jsonObject) | ||
| 2320 | + // let stringData = String(data: data, encoding: .utf8) ?? "" | ||
| 2321 | + | ||
| 2322 | + // print("constructCampaignParams: " + stringData) | ||
| 2323 | + // return stringData | ||
| 2324 | + | ||
| 2325 | + do { | ||
| 2305 | let encoder = JSONEncoder() | 2326 | let encoder = JSONEncoder() |
| 2306 | encoder.outputFormatting = .prettyPrinted | 2327 | encoder.outputFormatting = .prettyPrinted |
| 2307 | - let data = try! encoder.encode(jsonObject) | 2328 | + let data = try encoder.encode(jsonObject) |
| 2308 | let stringData = String(data: data, encoding: .utf8) ?? "" | 2329 | let stringData = String(data: data, encoding: .utf8) ?? "" |
| 2309 | - | ||
| 2310 | print("constructCampaignParams: " + stringData) | 2330 | print("constructCampaignParams: " + stringData) |
| 2311 | return stringData | 2331 | return stringData |
| 2332 | + } catch { | ||
| 2333 | + print("Error encoding campaign params: \(error)") | ||
| 2334 | + return "{}" | ||
| 2335 | + } | ||
| 2312 | 2336 | ||
| 2313 | // do { | 2337 | // do { |
| 2314 | // let data = try JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted) | 2338 | // let data = try JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted) |
| ... | @@ -2328,26 +2352,38 @@ public class swiftApi { | ... | @@ -2328,26 +2352,38 @@ public class swiftApi { |
| 2328 | let campaignInfo = instanceOfMyApi.provideInfoForCampaign() | 2352 | let campaignInfo = instanceOfMyApi.provideInfoForCampaign() |
| 2329 | 2353 | ||
| 2330 | let jsonObject: [String: String] = [ | 2354 | let jsonObject: [String: String] = [ |
| 2331 | - "web_id": (campaignInfo?["web_id"] as! String), | 2355 | + "web_id": (campaignInfo?["web_id"] as? String ?? ""), |
| 2332 | - "app_uuid": (campaignInfo?["app_uuid"] as! String), | 2356 | + "app_uuid": (campaignInfo?["app_uuid"] as? String ?? ""), |
| 2333 | - "api_key": (campaignInfo?["api_key"] as! String), | 2357 | + "api_key": (campaignInfo?["api_key"] as? String ?? ""), |
| 2334 | "session_uuid": (campaign.session_uuid ?? ""), | 2358 | "session_uuid": (campaign.session_uuid ?? ""), |
| 2335 | - "access_token": (campaignInfo?["access_token"] as! String), | 2359 | + "access_token": (campaignInfo?["access_token"] as? String ?? ""), |
| 2336 | - "refresh_token": (campaignInfo?["refresh_token"] as! String), | 2360 | + "refresh_token": (campaignInfo?["refresh_token"] as? String ?? ""), |
| 2337 | - "client_id": (campaignInfo?["client_id"] as! String), | 2361 | + "client_id": (campaignInfo?["client_id"] as? String ?? ""), |
| 2338 | - "client_secret": (campaignInfo?["client_secret"] as! String), | 2362 | + "client_secret": (campaignInfo?["client_secret"] as? String ?? ""), |
| 2339 | "from_widget": (from_widget ? "true" : "false"), | 2363 | "from_widget": (from_widget ? "true" : "false"), |
| 2340 | "lan": swiftApi().getApplicationLocale(), | 2364 | "lan": swiftApi().getApplicationLocale(), |
| 2341 | "dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false") | 2365 | "dark": (swiftApi().getIsDarkModeEnabled() ? "true" : "false") |
| 2342 | ] | 2366 | ] |
| 2343 | 2367 | ||
| 2368 | + // let encoder = JSONEncoder() | ||
| 2369 | + // encoder.outputFormatting = .prettyPrinted | ||
| 2370 | + // let data = try! encoder.encode(jsonObject) | ||
| 2371 | + // let stringData = String(data: data, encoding: .utf8) ?? "" | ||
| 2372 | + | ||
| 2373 | + // print("constructCampaignParams: " + stringData) | ||
| 2374 | + // return stringData | ||
| 2375 | + | ||
| 2376 | + do { | ||
| 2344 | let encoder = JSONEncoder() | 2377 | let encoder = JSONEncoder() |
| 2345 | encoder.outputFormatting = .prettyPrinted | 2378 | encoder.outputFormatting = .prettyPrinted |
| 2346 | - let data = try! encoder.encode(jsonObject) | 2379 | + let data = try encoder.encode(jsonObject) |
| 2347 | let stringData = String(data: data, encoding: .utf8) ?? "" | 2380 | let stringData = String(data: data, encoding: .utf8) ?? "" |
| 2348 | - | ||
| 2349 | print("constructCampaignParams: " + stringData) | 2381 | print("constructCampaignParams: " + stringData) |
| 2350 | return stringData | 2382 | return stringData |
| 2383 | + } catch { | ||
| 2384 | + print("Error encoding campaign params: \(error)") | ||
| 2385 | + return "{}" | ||
| 2386 | + } | ||
| 2351 | 2387 | ||
| 2352 | // do { | 2388 | // do { |
| 2353 | // let data = try JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted) | 2389 | // let data = try JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted) |
| ... | @@ -2414,13 +2450,25 @@ public class swiftApi { | ... | @@ -2414,13 +2450,25 @@ public class swiftApi { |
| 2414 | "ZONE": (campaign._zone) | 2450 | "ZONE": (campaign._zone) |
| 2415 | ] | 2451 | ] |
| 2416 | 2452 | ||
| 2453 | + // let encoder = JSONEncoder() | ||
| 2454 | + // encoder.outputFormatting = .prettyPrinted | ||
| 2455 | + // let data = try! encoder.encode(jsonObject) | ||
| 2456 | + // let stringData = String(data: data, encoding: .utf8) ?? "" | ||
| 2457 | + | ||
| 2458 | + // print("constructCcmsParams: " + stringData) | ||
| 2459 | + // return stringData | ||
| 2460 | + | ||
| 2461 | + do { | ||
| 2417 | let encoder = JSONEncoder() | 2462 | let encoder = JSONEncoder() |
| 2418 | encoder.outputFormatting = .prettyPrinted | 2463 | encoder.outputFormatting = .prettyPrinted |
| 2419 | - let data = try! encoder.encode(jsonObject) | 2464 | + let data = try encoder.encode(jsonObject) |
| 2420 | let stringData = String(data: data, encoding: .utf8) ?? "" | 2465 | let stringData = String(data: data, encoding: .utf8) ?? "" |
| 2421 | - | ||
| 2422 | print("constructCcmsParams: " + stringData) | 2466 | print("constructCcmsParams: " + stringData) |
| 2423 | return stringData | 2467 | return stringData |
| 2468 | + } catch { | ||
| 2469 | + print("Error encoding ccms params: \(error)") | ||
| 2470 | + return "{}" | ||
| 2471 | + } | ||
| 2424 | break; | 2472 | break; |
| 2425 | } | 2473 | } |
| 2426 | } | 2474 | } |
| ... | @@ -2478,13 +2526,25 @@ public class swiftApi { | ... | @@ -2478,13 +2526,25 @@ public class swiftApi { |
| 2478 | "ZONE": (ccmsCampaign._zone) | 2526 | "ZONE": (ccmsCampaign._zone) |
| 2479 | ] | 2527 | ] |
| 2480 | 2528 | ||
| 2529 | + // let encoder = JSONEncoder() | ||
| 2530 | + // encoder.outputFormatting = .prettyPrinted | ||
| 2531 | + // let data = try! encoder.encode(jsonObject) | ||
| 2532 | + // let stringData = String(data: data, encoding: .utf8) ?? "" | ||
| 2533 | + | ||
| 2534 | + // print("constructCcmsParams: " + stringData) | ||
| 2535 | + // return stringData | ||
| 2536 | + | ||
| 2537 | + do { | ||
| 2481 | let encoder = JSONEncoder() | 2538 | let encoder = JSONEncoder() |
| 2482 | encoder.outputFormatting = .prettyPrinted | 2539 | encoder.outputFormatting = .prettyPrinted |
| 2483 | - let data = try! encoder.encode(jsonObject) | 2540 | + let data = try encoder.encode(jsonObject) |
| 2484 | let stringData = String(data: data, encoding: .utf8) ?? "" | 2541 | let stringData = String(data: data, encoding: .utf8) ?? "" |
| 2485 | - | ||
| 2486 | print("constructCcmsParams: " + stringData) | 2542 | print("constructCcmsParams: " + stringData) |
| 2487 | return stringData | 2543 | return stringData |
| 2544 | + } catch { | ||
| 2545 | + print("Error encoding ccms params: \(error)") | ||
| 2546 | + return "{}" | ||
| 2547 | + } | ||
| 2488 | } | 2548 | } |
| 2489 | 2549 | ||
| 2490 | 2550 | ||
| ... | @@ -4055,6 +4115,11 @@ public class swiftApi { | ... | @@ -4055,6 +4115,11 @@ public class swiftApi { |
| 4055 | } | 4115 | } |
| 4056 | 4116 | ||
| 4057 | public func openSupermarketsMap(_ controller: UIViewController) -> Void { | 4117 | public func openSupermarketsMap(_ controller: UIViewController) -> Void { |
| 4118 | + let instanceOfMyApi = MyApi() | ||
| 4119 | + let isInitialised = instanceOfMyApi.sdkInitialised(); | ||
| 4120 | + | ||
| 4121 | + if (isInitialised == true) { | ||
| 4122 | + | ||
| 4058 | let status = swiftApi().getNetworkStatus() | 4123 | let status = swiftApi().getNetworkStatus() |
| 4059 | if (status == -1 || status == 0) { | 4124 | if (status == -1 || status == 0) { |
| 4060 | swiftApi().showDialog(controller, "Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.") | 4125 | swiftApi().showDialog(controller, "Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.") |
| ... | @@ -4078,9 +4143,17 @@ public class swiftApi { | ... | @@ -4078,9 +4143,17 @@ public class swiftApi { |
| 4078 | controller.present(vc, animated: true, completion: nil) | 4143 | controller.present(vc, animated: true, completion: nil) |
| 4079 | } | 4144 | } |
| 4080 | } | 4145 | } |
| 4146 | + } else { | ||
| 4147 | + print("Warply SDK is not initialised. Please initialise it before calling it's methods.") | ||
| 4148 | + } | ||
| 4081 | } | 4149 | } |
| 4082 | 4150 | ||
| 4083 | public func openSuperMarketsFlow(_ controller: UIViewController) -> Void { | 4151 | public func openSuperMarketsFlow(_ controller: UIViewController) -> Void { |
| 4152 | + let instanceOfMyApi = MyApi() | ||
| 4153 | + let isInitialised = instanceOfMyApi.sdkInitialised(); | ||
| 4154 | + | ||
| 4155 | + if (isInitialised == true) { | ||
| 4156 | + | ||
| 4084 | let status = swiftApi().getNetworkStatus() | 4157 | let status = swiftApi().getNetworkStatus() |
| 4085 | if (status == -1 || status == 0) { | 4158 | if (status == -1 || status == 0) { |
| 4086 | swiftApi().showDialog(controller, "Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.") | 4159 | swiftApi().showDialog(controller, "Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.") |
| ... | @@ -4105,6 +4178,9 @@ public class swiftApi { | ... | @@ -4105,6 +4178,9 @@ public class swiftApi { |
| 4105 | } | 4178 | } |
| 4106 | } | 4179 | } |
| 4107 | } | 4180 | } |
| 4181 | + } else { | ||
| 4182 | + print("Warply SDK is not initialised. Please initialise it before calling it's methods.") | ||
| 4183 | + } | ||
| 4108 | } | 4184 | } |
| 4109 | 4185 | ||
| 4110 | 4186 | ||
| ... | @@ -4431,4 +4507,11 @@ public class swiftApi { | ... | @@ -4431,4 +4507,11 @@ public class swiftApi { |
| 4431 | } | 4507 | } |
| 4432 | } | 4508 | } |
| 4433 | 4509 | ||
| 4510 | + public func isSDKInitialized() -> Bool { | ||
| 4511 | + let instanceOfMyApi = MyApi() | ||
| 4512 | + let isInitialised = instanceOfMyApi.sdkInitialised(); | ||
| 4513 | + | ||
| 4514 | + return isInitialised | ||
| 4515 | + } | ||
| 4516 | + | ||
| 4434 | } | 4517 | } | ... | ... |
-
Please register or login to post a comment