How to get the user's country calling code in iOS?

后端 未结 13 2004
终归单人心
终归单人心 2020-12-23 13:24

I am developing an iOS app in which the user enters their mobile number. How do I get their country calling code? For example, if a user is in India, then +91 s

13条回答
  •  温柔的废话
    2020-12-23 13:42

    If you want to prefixed calling country code automatically then you need to get user's country code pragmatically and Drag & drop src Folder in your code Its looks like this:

    if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String {
            print(countryCode)
            let strCode = Countries.countryFromCountryCode(countryCode: countryCode)
            btnPhoneCode.setTitle("+\(strCode.phoneExtension)", for: .normal)
    
        }
    

    It works for me, Hope will help you too. :)

提交回复
热议问题