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

Re: Re: Accessing private APIs

Posted by: thomasg_peters <thomasg_peters@...>

Hi Berni how are you? Thank you for sharing the information about accessing APIs.

I need to review this because this is something that I’ve been wanting to do for a long time and just have not understood exactly the process of making toolbox calls. It’s renewing my interest.
This may spin off more threads.

Thomas Peters

Accenture, Delivery / Development Leader

On Mar 7, 2022, at 5:19 AM, Bernie <[email protected]&gt; wrote:


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: %@&quot;,fn DialingCodeForISOCountryCode(@"gb"))
NSLog(@"The dialing code for United States is: %@&quot;,fn DialingCodeForISOCountryCode(@"us"))
NSLog(@"The dialing code for Spain is: %@&quot;,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: %@&quot;,fn DialingCodeForISOCountryCode(@"gb"))
NSLog(@"The dialing code for United States is: %@&quot;,fn DialingCodeForISOCountryCode(@"us"))
NSLog(@"The dialing code for Spain is: %@&quot;,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/

=