diff --git a/README.md b/README.md index a5f5691..0a437ca 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ FMNetwork: (contains every data about a SIM card and its connected network) * mnc: String (returns the Mobile Network Code (MNC) of the SIM card carrier, "--" by default) * land: String (returns the uppercased 2-digit ISO country code* of the SIM card carrier, "--" by default) * type: FMNetworkType (.sim, .esim or .current) + * plmns: [PLMN] (returns the list of mcc and mnc of the declared roaming PLMNs, [] by default ) * network: FMNetworkData (contains every data about the connected network of a SIM card) * name: String (returns the name of the connected network, "Carrier" by default) * mcc: String (returns the Mobile Country Code (MCC) of the connected network, "---" by default) @@ -68,12 +69,14 @@ FMNetwork: (contains every data about a SIM card and its connected network) * setupDone: Bool? (returns the declared FMobile setup done property, true/nil by default) * minimalSetup: Bool? (returns the declared FMobile minimal setup property, true/nil by default) * disableFMobileCore: Bool? (returns the declared FMobile national roaming core disability status, true/nil by default) - * countriesData: [String]? (returns the declared ISO country codes included for data only at no charge, nil by default) - * countriesVoice: [String]? (returns the declared ISO country codes included for voice only at no charge, nil by default) - * countriesVData: [String]? (returns the declared ISO country codes included for voice and data only at no charge, nil by default) + * countriesData: [String]? (returns the declared 2-digit ISO country codes included for data only at no charge, nil by default) + * countriesVoice: [String]? (returns the declared 2-digit ISO country codes included for voice only at no charge, nil by default) + * countriesVData: [String]? (returns the declared 2-digit ISO country codes included for voice and data only at no charge, nil by default) * carrierServices: [[String]]? (returns the declared Carrier Services available to be displayed and used inside apps, nil by default) * roamLTE: Bool? (returns the declared 4G LTE national roaming status, nil by default) * roam5G: Bool? (returns the declared 5G national roaming status, nil by default) + * chasedmnc: String? (returns the MNC used to detect the national roaming network - if mnc, requires a speedtest to detect the national roaming, mnc/nil by default) + * nrdec: Bool? (returns the national roaming declaration status - if true, chasedmnc = mnc, false/nil by default) *There is an exception for International carriers. They might return the non-standardised 2-digits code "WD", standing for World. diff --git a/Sources/FMNetwork/FMNetwork.swift b/Sources/FMNetwork/FMNetwork.swift index 0276870..016869c 100644 --- a/Sources/FMNetwork/FMNetwork.swift +++ b/Sources/FMNetwork/FMNetwork.swift @@ -61,9 +61,25 @@ public class FMNetwork { public func loadFMobileService(completionHandler: @escaping (Bool) -> ()) { FMobileService.fetch(forMCC: card.mcc, andMNC: card.mnc) { (service) in if (service != nil) { + service?.europeanCheck() FMobileService.replace(service?.hp ?? "", { service?.hp = $0 }, CTRadioAccessTechnologyWCDMA) FMobileService.replace(service?.nrp ?? "", { service?.nrp = $0 }, CTRadioAccessTechnologyHSDPA) + + for value in self.card.plmns { + if value.mcc == service?.mcc ?? "" && value.mnc == service?.itimnc ?? "" { + service?.nrdec = true + } + } + + if service?.nrdec ?? false { + service?.chasedmnc = service?.mnc + } else { + service?.chasedmnc = service?.itimnc + } + + service?.minimalSetup = self.card.eligibleminimalsetup + self.fmobile = service completionHandler(true) } else { @@ -214,7 +230,21 @@ public class FMNetwork { } let arraysim = testsim["StatusBarImages"] as? NSArray ?? NSArray.init(array: [0]) let secondDictsim = NSDictionary(dictionary: arraysim[0] as? Dictionary ?? NSDictionary() as? Dictionary ?? Dictionary()) - + + let array = testsim["SupportedPLMNs"] as? NSArray ?? NSArray.init(array: [0]) + + if array.count <= 1 { + card.eligibleminimalsetup = true + } + + for item in array { + if let value = item as? String, (value.count == 5 || value.count == 6) { + let plmnmcc = String(value.prefix(3)) + let plmnmnc = String(value.count == 6 ? value.suffix(3) : value.suffix(2)) + card.plmns.append(PLMN(mcc: plmnmcc, mnc: plmnmnc)) + } + } + card.simname = (secondDictsim["StatusBarCarrierName"] as? String) ?? "Carrier" card.fullname = (secondDictsim["CarrierName"] as? String) ?? "Carrier" } catch {} diff --git a/Sources/FMNetwork/Utilities/FMNetwork/FMNetworkSIMData.swift b/Sources/FMNetwork/Utilities/FMNetwork/FMNetworkSIMData.swift index 6025513..e03c95c 100644 --- a/Sources/FMNetwork/Utilities/FMNetwork/FMNetworkSIMData.swift +++ b/Sources/FMNetwork/Utilities/FMNetwork/FMNetworkSIMData.swift @@ -97,6 +97,16 @@ public class FMNetworkSIMData { public var type: FMNetworkType + /** This propery returns the list of the declared roaming PLMNs of the SIM card carrier. + + Example: + * plmns == [PLMN(mcc: 208, mnc: 00), PLMN(mcc: 208, mnc: 01), PLMN(mcc: 208, mnc: 02)] (the declared roaming PLMNs for Free Mobile) + + - Warning: This variable returns [] (PLMN) in case no value was not found. + */ + public var plmns: [PLMN] + + // DEPRECATED SECTION -------------------------------------- @@ -105,6 +115,20 @@ public class FMNetworkSIMData { // INTERNAL SECTION ---------------------------------------- + + /** This propery returns the full name of the company running the SIM card carrier. + + - Remark: This variable is temporary and used to set the fmobile.minimalsetup property when using the FMobile API service, and therefore it is recommended to keep it internal. This variable returns the minimal setup eligibility of the carrier of the SIM card. + + Example: + * eligibleminimalsetup == false (minimal setup eligibility for Free Mobile) + + - Warning: This variable returns true by default. + - Important: Use fmobile.minimalsetup instead + */ + internal var eligibleminimalsetup: Bool + + /** This propery returns the full name of the company running the SIM card carrier. - Remark: This variable is unstable and therefore it is recommended to keep it internal. This variable returns the full name of the carrier of the SIM card. @@ -154,7 +178,7 @@ public class FMNetworkSIMData { /// - carrier: carrier to add to the object /// - active: active status to add to the object /// - type: type to add to the object - internal init(mcc: String = String(), mnc: String = String(), land: String = String(), name: String = String(), fullname: String = String(), data: String = String(), simname: String = String(), carrier: CTCarrier = CTCarrier(), active: Bool = false, type: FMNetworkType = .sim) { + internal init(mcc: String = String(), mnc: String = String(), land: String = String(), name: String = String(), fullname: String = String(), data: String = String(), simname: String = String(), carrier: CTCarrier = CTCarrier(), active: Bool = false, type: FMNetworkType = .sim, plmns: [PLMN] = [PLMN](), eligibleminimalsetup: Bool = true) { self.mcc = mcc self.mnc = mnc self.land = land @@ -165,6 +189,8 @@ public class FMNetworkSIMData { self.carrier = carrier self.active = active self.type = type + self.plmns = plmns + self.eligibleminimalsetup = eligibleminimalsetup } } diff --git a/Sources/FMNetwork/Utilities/Other/FMobileService.swift b/Sources/FMNetwork/Utilities/Other/FMobileService.swift index bc3190f..c78ae0b 100644 --- a/Sources/FMNetwork/Utilities/Other/FMobileService.swift +++ b/Sources/FMNetwork/Utilities/Other/FMobileService.swift @@ -254,6 +254,29 @@ public class FMobileService: Codable { */ public var roam5G: Bool? + /** This propery returns the Mobile Network Code (MNC) used to detect the national roaming network, as declared at the FMobile API service, as a String. It may be equal to mnc or itimnc, depending on the nrdec property. If nrdec is equal to true, chasedmnc will be equal to mnc and you will need to do a speedtest in order to detect the national roaming. + ```text + Example: + chasedmnc == "15" (The MNC used to detect national roaming network for Free Mobile) + ``` + + - Attention: If you are dealing with national roaming, it would be best to check that the disableFMobileCore property is equal to false first. + - Attention: If chasedmnc is equal to mnc, you will need to do a speedtest in order to detect the national roaming. + - Warning: This variable will likely return mnc by default, but can also return nil in case something went wrong. + */ + public var chasedmnc: String? + + /** This propery returns the national roaming declaration status of the SIM card carrier, as a Bool. + + ```text + Example: + nrdec == true (The national roaming declaration status for Free Mobile) + ``` + + - Warning: If nrdec is equal to true, the roaming network is declared and chasedmnc will be equal to mnc, so you will need to do a speedtest in order to detect the national roaming. This variable returns nil in case something went wrong. + */ + public var nrdec: Bool? + // DEPRECATED SECTION -------------------------------------- diff --git a/Sources/FMNetwork/Utilities/Other/PLMN.swift b/Sources/FMNetwork/Utilities/Other/PLMN.swift new file mode 100644 index 0000000..b2c313f --- /dev/null +++ b/Sources/FMNetwork/Utilities/Other/PLMN.swift @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2020 Groupe MINASTE + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ +// +// PLMN.swift +// +// +// Created by PlugN on 21.12.20.. +// + +import Foundation + +/// This class contains data about a declared PLMN roaming network. +public class PLMN { + + /** This propery returns the Mobile Country Code (MCC) of the PLMN, as a String. + ```text + Example: + mcc == "208" (The MCC for France) + ``` + + - Warning: This variable has no default value. + */ + public var mcc: String + + /** This propery returns the Mobile Network Code (MNC) of the PLMN, as a String. + ```text + Example: + mnc == "01" (The MNC for Orange France) + ``` + + - Warning: This variable has no default value. + */ + public var mnc: String + + + /// Initialize a PLMN object + /// - Parameters: + /// - mcc: The Mobile Country Code (MCC) of the PLMN + /// - mnc: The Mobile Network Code (MNC) of the PLMN + public init(mcc: String, mnc: String) { + self.mcc = mcc + self.mnc = mnc + } +}