Forum Navigation
You need to log in to create posts and topics.

Re: Accessing private APIs

Posted by: bernfbe <bernfbe@...>


The methods for CNPhoneNumber lists an interesting, private class method: dialingCodeForISOCountryCode:

But how do we call that?

The method takes an argument (the country code) but ValueForKey doesn't seem to give us that option.

One way is to fallback to Ken's original plan and ignore or silence the warning.
// ---------------
//#build CompilerOptions @"-Wno-objc-method-access"// <-- silence all "method not found" warnings
include "NSLog.incl"
include "Tlbx Contacts.incl"

local fn DialingCodeForISOCountryCode( countryCode as CFStringRef ) as CFStringRef
'~'1
CFStringRef dialingCode
cln dialingCode = (__bridge CFStringRef)[CNPhoneNumber dialingCodeForISOCountryCode:countryCode];
end fn = dialingCode

NSLog(@"The dialing code for Great Britain is: %@",fn DialingCodeForISOCountryCode(@"gb"))
NSLog(@"The dialing code for United States is: %@",fn DialingCodeForISOCountryCode(@"us"))
NSLog(@"The dialing code for Spain is: %@",fn DialingCodeForISOCountryCode(@"es"))

HandleEvents
// ---------------



Another way is to jump through hoops.
// ---------------
include "NSLog.incl"
include "Tlbx Contacts.incl"

local fn DialingCodeForISOCountryCode( countryCode as CFStringRef ) as CFStringRef
'~'1
CFStringRef dialingCode
SELRef selector = fn SelectorFromString(@"dialingCodeForISOCountryCode:")
MethodSignatureRef signature
cln signature = [[CNPhoneNumber class] methodSignatureForSelector:selector];
InvocationRef invocation = fn InvocationWithMethodSignature( signature )
InvocationSetTarget( invocation, fn ClassFromString( @"CNPhoneNumber" ) )
InvocationSetSelector( invocation, selector )
InvocationSetArgumentAtIndex( invocation, @countryCode, 2 )
InvocationInvoke( invocation )
InvocationGetReturnValue( invocation, @dialingCode )
end fn = dialingCode

void local fn DoIt
'~'1
NSLog(@"The dialing code for Great Britain is: %@",fn DialingCodeForISOCountryCode(@"gb"))
NSLog(@"The dialing code for United States is: %@",fn DialingCodeForISOCountryCode(@"us"))
NSLog(@"The dialing code for Spain is: %@",fn DialingCodeForISOCountryCode(@"es"))
end fn

fn DoIt

HandleEvents
// ---------------



--
To unsubscribe, send ANY message to: [email protected] To access the list archives, go to: http://freegroups.net/groups/futurebasic/