libPhoneNumber-iOS icon indicating copy to clipboard operation
libPhoneNumber-iOS copied to clipboard

[[NBPhoneNumberUtil new] getCountryCodeForRegion:] always returns @0

Open Hopreeeenjust opened this issue 8 years ago • 11 comments

I'm using 0.9.2 libPhoneNumber and it appeared that [[NBPhoneNumberUtil new] getCountryCodeForRegion:] method always returns 0 for valid country codes.

The reason is
Class metaClass = NSClassFromString(className); always nil in getMetadataForRegion: method of the lib.

UPD: Backing up to 0.8.16 solves the issue. But 0.9.2 is still buggy.

Hopreeeenjust avatar Jan 04 '17 09:01 Hopreeeenjust

Sorry for late, Could you check with latest updated code ?

iziz avatar Feb 07 '17 15:02 iziz

"Pod update" command still updates to 0.9.2 Installing libPhoneNumber-iOS 0.9.2 (was 0.8.16)

So the issue is still there

Hopreeeenjust avatar Feb 09 '17 10:02 Hopreeeenjust

Maybe you should check Podfile or some cache. http://cocoapods.org/?q=libPhoneNumber-iOS show 0.9.3

iziz avatar Feb 09 '17 10:02 iziz

No, podfile is OK. When trying to install pod 'libPhoneNumber-iOS', '0.9.3' i get

[!] Unable to satisfy the following requirements:

  • 'libPhoneNumber-iOS (= 0.9.3)' required by 'Podfile'
  • 'libPhoneNumber-iOS (= 0.9.3)' required by 'Podfile'
  • 'libPhoneNumber-iOS (= 0.9.3)' required by 'Podfile'

None of your spec sources contain a spec satisfying the dependency: 'libPhoneNumber-iOS (= >0.9.3)'.

And if to set pod 'libPhoneNumber-iOS' or pod 'libPhoneNumber-iOS', '~> 0.9' it installs 0.9.2.

So i will check later when updated version will be available.

Hopreeeenjust avatar Feb 09 '17 10:02 Hopreeeenjust

Updated to 0.9.4. Would you check this ?

iziz avatar Feb 15 '17 16:02 iziz

Still the same issue with 0.9.4. NBMetadataHelper fails to get metaclass and returns nil.

Hopreeeenjust avatar Feb 15 '17 17:02 Hopreeeenjust

It works good with below code, I can't find out your issue. Show me your sample code to find issue.

    NSLog(@"--------- %@", [phoneUtil getCountryCodeForRegion:@"KR"]);
    NSLog(@"--------- %@", [phoneUtil getCountryCodeForRegion:@"JP"]);

iziz avatar Feb 15 '17 18:02 iziz

I spent some hours for investigation and here is the reason: i do not use -ObjC flag in Build Settings > Other Linker flags. Also i do not use $(inherited) for some purposes. So -ObjC flag is not represented in this section.

Without this flag Class metaClass = NSClassFromString(className); returnes nil.

But strange thing here is 0.8.16 works fine even if -ObjC flag is not used.

Hopreeeenjust avatar Feb 15 '17 18:02 Hopreeeenjust

OK Thanks, I will find out the reason.

iziz avatar Feb 16 '17 01:02 iziz

Here's what was happening:

Objective C deadstrips by class (not by method). If you don't have a reference to a class directly in your code by name (i.e. [Foo aMethod]) and you have deadstripping on, the compiler will deadstrip Foo. With the way the old code was written, there were never class references for any of the metaclasses, as they were only accessed via NSClassFromString, so the compiler was happily deadstripping them and NSClassFromString would return null, because the class wasn't being linked in. Using the -ObjC flag forces the linker to include ALL objective C code, so it worked.

Good news is that once https://github.com/iziz/libPhoneNumber-iOS/pull/175 is in, it should work for you with the -ObjC flag again, because it has gotten rid of using NSClassFromString to get the classes.

dmaclach avatar Mar 20 '17 04:03 dmaclach

Good news! I was forced to start using -ObjC flag again, but hope this "fix" will help someone in the future.

Hopreeeenjust avatar Mar 20 '17 05:03 Hopreeeenjust