Manos Chorianopoulos

fix getProfile crash

...@@ -1826,34 +1826,51 @@ public class swiftApi { ...@@ -1826,34 +1826,51 @@ public class swiftApi {
1826 self.optin_sms_segmentation = optin?["sms_segmentation"] as? Bool? ?? false 1826 self.optin_sms_segmentation = optin?["sms_segmentation"] as? Bool? ?? false
1827 1827
1828 // profile_metadata 1828 // profile_metadata
1829 - let profile_metadata_json = dictionary["profile_metadata"] as AnyObject 1829 + if let profile_metadata_json = dictionary["profile_metadata"] as? AnyObject {
1830 - var profile_metadata_parsed:[String: Any] 1830 + if ((!(profile_metadata_json is NSNull)) && (profile_metadata_json != nil)) {
1831 - 1831 + var profile_metadata_parsed:[String: Any]
1832 - let json = profile_metadata_json.data(using: String.Encoding.utf8.rawValue) 1832 +
1833 - do { 1833 + let json = profile_metadata_json.data(using: String.Encoding.utf8.rawValue)
1834 - if let jsonArray = try JSONSerialization.jsonObject(with: json!, options: .allowFragments) as? [String:AnyObject] 1834 + do {
1835 - { 1835 + if let jsonArray = try JSONSerialization.jsonObject(with: json!, options: .allowFragments) as? [String:AnyObject]
1836 - profile_metadata_parsed = jsonArray; 1836 + {
1837 - self.profile_metadata = profile_metadata_parsed as? [String: Any]? ?? [String: Any]() 1837 + profile_metadata_parsed = jsonArray;
1838 - self.badge = profile_metadata_parsed["badge"] as? String? ?? "" 1838 + self.profile_metadata = profile_metadata_parsed as? [String: Any]? ?? [String: Any]()
1839 - self.msisdnList = profile_metadata_parsed["msisdnList"] as? Array<String>? ?? [] 1839 + self.badge = profile_metadata_parsed["badge"] as? String? ?? ""
1840 - self.answered = profile_metadata_parsed["answered"] as? Bool? ?? false 1840 + self.msisdnList = profile_metadata_parsed["msisdnList"] as? Array<String>? ?? []
1841 - self.nonTelco = profile_metadata_parsed["nonTelco"] as? Bool? ?? false 1841 + self.answered = profile_metadata_parsed["answered"] as? Bool? ?? false
1842 + self.nonTelco = profile_metadata_parsed["nonTelco"] as? Bool? ?? false
1843 + } else {
1844 + self.profile_metadata = [String: Any]()
1845 + self.badge = ""
1846 + self.msisdnList = []
1847 + self.answered = false
1848 + self.nonTelco = false
1849 + print("bad json")
1850 + }
1851 + } catch let error as NSError {
1852 + self.profile_metadata = [String: Any]()
1853 + self.badge = ""
1854 + self.msisdnList = []
1855 + self.answered = false
1856 + self.nonTelco = false
1857 + print(error)
1858 + }
1859 +
1842 } else { 1860 } else {
1843 self.profile_metadata = [String: Any]() 1861 self.profile_metadata = [String: Any]()
1844 self.badge = "" 1862 self.badge = ""
1845 self.msisdnList = [] 1863 self.msisdnList = []
1846 self.answered = false 1864 self.answered = false
1847 self.nonTelco = false 1865 self.nonTelco = false
1848 - print("bad json")
1849 } 1866 }
1850 - } catch let error as NSError { 1867 +
1868 + } else {
1851 self.profile_metadata = [String: Any]() 1869 self.profile_metadata = [String: Any]()
1852 self.badge = "" 1870 self.badge = ""
1853 self.msisdnList = [] 1871 self.msisdnList = []
1854 self.answered = false 1872 self.answered = false
1855 self.nonTelco = false 1873 self.nonTelco = false
1856 - print(error)
1857 } 1874 }
1858 1875
1859 } 1876 }
...@@ -4730,25 +4747,35 @@ public class swiftApi { ...@@ -4730,25 +4747,35 @@ public class swiftApi {
4730 self.date = "" 4747 self.date = ""
4731 } 4748 }
4732 4749
4733 - let transaction_metadata_json = dictionary["transaction_metadata"] as AnyObject 4750 + if let transaction_metadata_json = dictionary["transaction_metadata"] as? AnyObject {
4734 - var transaction_metadata_parsed:[String: Any] 4751 + if ((!(transaction_metadata_json is NSNull)) && (transaction_metadata_json != nil)) {
4735 - 4752 +
4736 - let json = transaction_metadata_json.data(using: String.Encoding.utf8.rawValue) 4753 + var transaction_metadata_parsed:[String: Any]
4737 - do { 4754 +
4738 - if let jsonArray = try JSONSerialization.jsonObject(with: json!, options: .allowFragments) as? [String:AnyObject] 4755 + let json = transaction_metadata_json.data(using: String.Encoding.utf8.rawValue)
4739 - { 4756 + do {
4740 - transaction_metadata_parsed = jsonArray; 4757 + if let jsonArray = try JSONSerialization.jsonObject(with: json!, options: .allowFragments) as? [String:AnyObject]
4741 - self.receiver_msisdn = transaction_metadata_parsed["receiver_msisdn"] as? String? ?? "" 4758 + {
4742 - self.sender_msisdn = transaction_metadata_parsed["sender_msisdn"] as? String? ?? "" 4759 + transaction_metadata_parsed = jsonArray;
4760 + self.receiver_msisdn = transaction_metadata_parsed["receiver_msisdn"] as? String? ?? ""
4761 + self.sender_msisdn = transaction_metadata_parsed["sender_msisdn"] as? String? ?? ""
4762 + } else {
4763 + self.receiver_msisdn = ""
4764 + self.sender_msisdn = ""
4765 + print("bad json")
4766 + }
4767 + } catch let error as NSError {
4768 + self.receiver_msisdn = ""
4769 + self.sender_msisdn = ""
4770 + print(error)
4771 + }
4743 } else { 4772 } else {
4744 self.receiver_msisdn = "" 4773 self.receiver_msisdn = ""
4745 self.sender_msisdn = "" 4774 self.sender_msisdn = ""
4746 - print("bad json")
4747 } 4775 }
4748 - } catch let error as NSError { 4776 + } else {
4749 self.receiver_msisdn = "" 4777 self.receiver_msisdn = ""
4750 self.sender_msisdn = "" 4778 self.sender_msisdn = ""
4751 - print(error)
4752 } 4779 }
4753 } 4780 }
4754 4781
......