Forum breadcrumbs - You are here:WeLoveGod RallysPublic Forums: futurebasicRe: Re: Accessing private APIs
You need to log in to create posts and topics.
Re: Re: Accessing private APIs
77,940 Posts
#1 · March 7, 2022, 9:42 am
Quote from Forum Archives on March 7, 2022, 9:42 amPosted 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 PetersAccenture, Delivery / Development LeaderOn Mar 7, 2022, at 5:19 AM, Bernie <[email protected]> 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" warningsinclude "NSLog.incl"include "Tlbx Contacts.incl"
local fn DialingCodeForISOCountryCode( countryCode as CFStringRef ) as CFStringRef'~'1CFStringRef dialingCodecln 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'~'1CFStringRef dialingCodeSELRef selector = fn SelectorFromString(@"dialingCodeForISOCountryCode:")MethodSignatureRef signaturecln 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'~'1NSLog(@"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/=
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]> 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" warningsinclude "NSLog.incl"include "Tlbx Contacts.incl"
local fn DialingCodeForISOCountryCode( countryCode as CFStringRef ) as CFStringRef'~'1CFStringRef dialingCodecln 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'~'1CFStringRef dialingCodeSELRef selector = fn SelectorFromString(@"dialingCodeForISOCountryCode:")MethodSignatureRef signaturecln 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'~'1NSLog(@"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/=
Click for thumbs down.0Click for thumbs up.0