GithubHelp home page GithubHelp logo

Comments (16)

bguidolim avatar bguidolim commented on June 14, 2024

Are you sure you're not using any Beta software? Xcode and iOS?

from phonenumberkit.

keremerkan avatar keremerkan commented on June 14, 2024

Yep. Xcode 15 release version and iOS 17 and 16 simulators that it downloaded from scratch.

from phonenumberkit.

keremerkan avatar keremerkan commented on June 14, 2024

Again, this happens only on iOS 17 simulator. iOS 16 simulator or iOS 17 on device works correctly.

from phonenumberkit.

bguidolim avatar bguidolim commented on June 14, 2024

Command line tools set on Xcode to 15 release?
Asking that because I am not able to reproduce this issue.

from phonenumberkit.

keremerkan avatar keremerkan commented on June 14, 2024

Correct. I am testing it with the following simple code.

let phoneNumberKit = PhoneNumberKit()
    
let phoneNumber = try? phoneNumberKit.parse("+908504801234")
    
if phoneNumber != nil {
  let internationalNumber = phoneNumberKit.format(phoneNumber!, toType: .international)
  print(internationalNumber)
}
else {
  print("Phone number nil")
}

The number is valid. I tried it in 3 different projects to see if it has something to do with the project settings. All fail on iOS 17 simulator and work correctly on 16 simulator and 17 device.

from phonenumberkit.

bguidolim avatar bguidolim commented on June 14, 2024

Can you check the build number of your iOS 17 simulator?
Screenshot 2023-09-30 at 14 36 21

from phonenumberkit.

keremerkan avatar keremerkan commented on June 14, 2024

It is exactly the same with yours. Do you use an Apple silicon or Intel Mac? Perhaps the problem comes from the architecture of the Mac. I am on a MacBook Pro with an M2 Max.

from phonenumberkit.

bguidolim avatar bguidolim commented on June 14, 2024

M1 Pro here.

Well, I don't really know how to proceed. Maybe add a check for the simulator, since there is not way to simulate a SIM card on it anyway.

from phonenumberkit.

bguidolim avatar bguidolim commented on June 14, 2024

Can you check if it works for you?

from phonenumberkit.

keremerkan avatar keremerkan commented on June 14, 2024

No, does not work. because somehow

        let currentLocale = Locale.current
        if let countryCode = (currentLocale as NSLocale).object(forKey: .countryCode) as? String {
            return countryCode.uppercased()
        }

Still returns "001". But if I override that with "US" for example and return that, it works correctly. So, the following works:

        #if !targetEnvironment(simulator)
        #if canImport(Contacts)
        if #available(iOS 12.0, macOS 10.13, macCatalyst 13.1, watchOS 4.0, *) {
            // macCatalyst OS bug if language is set to Korean
            // CNContactsUserDefaults.shared().countryCode will return ko instead of kr
            // Failed parsing any phone number.
            let countryCode = CNContactsUserDefaults.shared().countryCode.uppercased()
            #if targetEnvironment(macCatalyst)
                if "ko".caseInsensitiveCompare(countryCode) == .orderedSame {
                    return "KR"
                }
            #endif
            return countryCode
        }
        #endif
        
        let currentLocale = Locale.current
        if let countryCode = (currentLocale as NSLocale).object(forKey: .countryCode) as? String {
            return countryCode.uppercased()
        }
        #endif

from phonenumberkit.

keremerkan avatar keremerkan commented on June 14, 2024

I believe it would make much more sense to check using regex, if the country code is a two letter string instead of this hack though. If it is not a 2 letter code, returning default would be the best course of action.

from phonenumberkit.

bguidolim avatar bguidolim commented on June 14, 2024

countryCode is deprecated: https://developer.apple.com/documentation/foundation/nslocale/1643060-countrycode
Using regionCode now: https://developer.apple.com/documentation/foundation/nslocale/4172868-regioncode

Since the code was using object(forKey:), there was no deprecation warning.

from phonenumberkit.

keremerkan avatar keremerkan commented on June 14, 2024

Well, I only suggested what I got in the first pull request. :)

By the way, I looked at the latest pull request and believe that if somehow the region code returns "01" instead of "001" (could happen in a future simulator), we could encounter the same bug. Checking if its length is 2 characters would not be enough in my opinion, also making sure it is letters only would make it better future-proof.

from phonenumberkit.

keremerkan avatar keremerkan commented on June 14, 2024

By the way, I believe this is indeed some bug within my Xcode installation now. I am unable to launch "Settings" app on iOS 17 simulator. I'll try to reinstall it.

from phonenumberkit.

keremerkan avatar keremerkan commented on June 14, 2024

After reinstalling the simulator, the problem disappeared. I still cannot launch "Settings" app on iPhone 15 Pro/Pro Max though, so the simulator definitely has some bugs that need to be fixed by Apple (iPhone 15 and 15 Plus does not have that problem). In any case, your latest pull request that includes regex checks will eliminate any problems about this issue.

from phonenumberkit.

keremerkan avatar keremerkan commented on June 14, 2024

After trying fastlane snapshot for screenshots, the issue appeared again. Looks like fastlane is partially responsible for this bug.

from phonenumberkit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.