Forum breadcrumbs - You are here:WeLoveGod RallysPublic Forums: futurebasicRe: Accessing private APIs
You need to log in to create posts and topics.
Re: Accessing private APIs
77,940 Posts
#1 · March 7, 2022, 5:18 am
Quote from Forum Archives on March 7, 2022, 5:18 amPosted 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" 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 = dialingCodeNSLog(@"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 = dialingCodevoid 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 fnfn DoItHandleEvents// -----------------
To unsubscribe, send ANY message to: [email protected] To access the list archives, go to: http://freegroups.net/groups/futurebasic/
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/
Click for thumbs down.0Click for thumbs up.0