libPhoneNumber-iOS
libPhoneNumber-iOS copied to clipboard
[[NBPhoneNumberUtil new] getCountryCodeForRegion:] always returns @0
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.
Sorry for late, Could you check with latest updated code ?
"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
Maybe you should check Podfile or some cache. http://cocoapods.org/?q=libPhoneNumber-iOS show 0.9.3
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.
Updated to 0.9.4. Would you check this ?
Still the same issue with 0.9.4. NBMetadataHelper fails to get metaclass and returns nil.
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"]);
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.
OK Thanks, I will find out the reason.
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.
Good news! I was forced to start using -ObjC flag again, but hope this "fix" will help someone in the future.