mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Stop using CTCarrier for country code detection due to it's deprecation
This commit is contained in:
parent
939b29770a
commit
5d967279b9
@ -1296,18 +1296,9 @@ public final class AuthorizationSequenceController: NavigationController, ASAuth
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static func defaultCountryCode() -> Int32 {
|
public static func defaultCountryCode() -> Int32 {
|
||||||
var countryId: String? = nil
|
let countryId = (Locale.current as NSLocale).object(forKey: .countryCode) as? String
|
||||||
let networkInfo = CTTelephonyNetworkInfo()
|
|
||||||
if let carrier = networkInfo.serviceSubscriberCellularProviders?.values.first {
|
|
||||||
countryId = carrier.isoCountryCode
|
|
||||||
}
|
|
||||||
|
|
||||||
if countryId == nil {
|
|
||||||
countryId = (Locale.current as NSLocale).object(forKey: .countryCode) as? String
|
|
||||||
}
|
|
||||||
|
|
||||||
var countryCode: Int32 = 1
|
var countryCode: Int32 = 1
|
||||||
|
|
||||||
if let countryId = countryId {
|
if let countryId = countryId {
|
||||||
let normalizedId = countryId.uppercased()
|
let normalizedId = countryId.uppercased()
|
||||||
for (code, idAndName) in countryCodeToIdAndName {
|
for (code, idAndName) in countryCodeToIdAndName {
|
||||||
|
@ -5,7 +5,6 @@ import Display
|
|||||||
import TelegramCore
|
import TelegramCore
|
||||||
import Postbox
|
import Postbox
|
||||||
import SwiftSignalKit
|
import SwiftSignalKit
|
||||||
import CoreTelephony
|
|
||||||
import TelegramPresentationData
|
import TelegramPresentationData
|
||||||
import AccountContext
|
import AccountContext
|
||||||
import AlertUI
|
import AlertUI
|
||||||
@ -382,17 +381,9 @@ extension SecureIdPlaintextFormInnerState {
|
|||||||
init(type: SecureIdPlaintextFormType, immediatelyAvailableValue: SecureIdValue?) {
|
init(type: SecureIdPlaintextFormType, immediatelyAvailableValue: SecureIdValue?) {
|
||||||
switch type {
|
switch type {
|
||||||
case .phone:
|
case .phone:
|
||||||
var countryId: String? = nil
|
let countryId = (Locale.current as NSLocale).object(forKey: .countryCode) as? String
|
||||||
if let carrier = CTTelephonyNetworkInfo().serviceSubscriberCellularProviders?.values.first {
|
|
||||||
countryId = carrier.isoCountryCode
|
|
||||||
}
|
|
||||||
|
|
||||||
if countryId == nil {
|
|
||||||
countryId = (Locale.current as NSLocale).object(forKey: .countryCode) as? String
|
|
||||||
}
|
|
||||||
|
|
||||||
var countryCodeAndId: (Int32, String) = (1, "US")
|
var countryCodeAndId: (Int32, String) = (1, "US")
|
||||||
|
|
||||||
if let countryId = countryId {
|
if let countryId = countryId {
|
||||||
let normalizedId = countryId.uppercased()
|
let normalizedId = countryId.uppercased()
|
||||||
for (code, idAndName) in countryCodeToIdAndName {
|
for (code, idAndName) in countryCodeToIdAndName {
|
||||||
|
@ -162,8 +162,26 @@ public func ChangePhoneNumberController(context: AccountContext) -> ViewControll
|
|||||||
}
|
}
|
||||||
|
|
||||||
Queue.mainQueue().justDispatch {
|
Queue.mainQueue().justDispatch {
|
||||||
controller.updateData(countryCode: AuthorizationSequenceController.defaultCountryCode(), countryName: nil, number: "")
|
let _ = (context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: context.account.peerId))
|
||||||
controller.updateCountryCode()
|
|> deliverOnMainQueue).start(next: { accountPeer in
|
||||||
|
guard let accountPeer, case let .user(user) = accountPeer else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let initialCountryCode: Int32
|
||||||
|
if let phone = user.phone {
|
||||||
|
if let (_, countryCode) = lookupCountryIdByNumber(phone, configuration: context.currentCountriesConfiguration.with { $0 }), let codeValue = Int32(countryCode.code) {
|
||||||
|
initialCountryCode = codeValue
|
||||||
|
} else {
|
||||||
|
initialCountryCode = AuthorizationSequenceController.defaultCountryCode()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
initialCountryCode = AuthorizationSequenceController.defaultCountryCode()
|
||||||
|
}
|
||||||
|
controller.updateData(countryCode: initialCountryCode, countryName: nil, number: "")
|
||||||
|
controller.updateCountryCode()
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return controller
|
return controller
|
||||||
|
@ -3,7 +3,6 @@ import UIKit
|
|||||||
import AsyncDisplayKit
|
import AsyncDisplayKit
|
||||||
import Display
|
import Display
|
||||||
import TelegramCore
|
import TelegramCore
|
||||||
import CoreTelephony
|
|
||||||
import TelegramPresentationData
|
import TelegramPresentationData
|
||||||
import PhoneInputNode
|
import PhoneInputNode
|
||||||
import CountrySelectionUI
|
import CountrySelectionUI
|
||||||
@ -211,18 +210,9 @@ final class ChangePhoneNumberControllerNode: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var countryId: String? = nil
|
let countryId = (Locale.current as NSLocale).object(forKey: .countryCode) as? String
|
||||||
let networkInfo = CTTelephonyNetworkInfo()
|
|
||||||
if let carrier = networkInfo.serviceSubscriberCellularProviders?.values.first {
|
|
||||||
countryId = carrier.isoCountryCode
|
|
||||||
}
|
|
||||||
|
|
||||||
if countryId == nil {
|
|
||||||
countryId = (Locale.current as NSLocale).object(forKey: .countryCode) as? String
|
|
||||||
}
|
|
||||||
|
|
||||||
var countryCodeAndId: (Int32, String) = (1, "US")
|
var countryCodeAndId: (Int32, String) = (1, "US")
|
||||||
|
|
||||||
if let countryId = countryId {
|
if let countryId = countryId {
|
||||||
let normalizedId = countryId.uppercased()
|
let normalizedId = countryId.uppercased()
|
||||||
for (code, idAndName) in countryCodeToIdAndName {
|
for (code, idAndName) in countryCodeToIdAndName {
|
||||||
|
@ -10,7 +10,6 @@ import ItemListUI
|
|||||||
import PresentationDataUtils
|
import PresentationDataUtils
|
||||||
import PhoneInputNode
|
import PhoneInputNode
|
||||||
import CountrySelectionUI
|
import CountrySelectionUI
|
||||||
import CoreTelephony
|
|
||||||
|
|
||||||
private func generateCountryButtonBackground(color: UIColor, strokeColor: UIColor) -> UIImage? {
|
private func generateCountryButtonBackground(color: UIColor, strokeColor: UIColor) -> UIImage? {
|
||||||
return generateImage(CGSize(width: 56, height: 44.0 + 6.0), rotatedContext: { size, context in
|
return generateImage(CGSize(width: 56, height: 44.0 + 6.0), rotatedContext: { size, context in
|
||||||
@ -234,18 +233,9 @@ class DeleteAccountPhoneItemNode: ListViewItemNode, ItemListItemNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var countryId: String? = nil
|
let countryId = (Locale.current as NSLocale).object(forKey: .countryCode) as? String
|
||||||
let networkInfo = CTTelephonyNetworkInfo()
|
|
||||||
if let carrier = networkInfo.serviceSubscriberCellularProviders?.values.first {
|
|
||||||
countryId = carrier.isoCountryCode
|
|
||||||
}
|
|
||||||
|
|
||||||
if countryId == nil {
|
|
||||||
countryId = (Locale.current as NSLocale).object(forKey: .countryCode) as? String
|
|
||||||
}
|
|
||||||
|
|
||||||
var countryCodeAndId: (Int32, String) = (1, "US")
|
var countryCodeAndId: (Int32, String) = (1, "US")
|
||||||
|
|
||||||
if let countryId = countryId {
|
if let countryId = countryId {
|
||||||
let normalizedId = countryId.uppercased()
|
let normalizedId = countryId.uppercased()
|
||||||
for (code, idAndName) in countryCodeToIdAndName {
|
for (code, idAndName) in countryCodeToIdAndName {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user