Error : Unable to bind foreign handler

LiveCode Builder is a language for extending LiveCode's capabilities, creating new object types as Widgets, and libraries that access lower-level APIs in OSes, applications, and DLLs.

Moderators: LCMark, LCfraser

Post Reply
Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Error : Unable to bind foreign handler

Post by Simon Knight » Thu Feb 06, 2020 3:59 pm

Hi,

Would someone be kind enough to have a look at the following foreign handler definition to see where my error is ?

Code: Select all

// Check authorisation to access Events - FAILS ???
// In Objective-C the type returned from authorizationStatusForEntityType is defined as NSInteger 
// which is an int on 32bit processor or long on 64bit processor.

private foreign handler ObjC_EKEventStoreAuthStatus(in pObj as ObjcID,in pEKEntityMaskEvent as CUint) \
			returns CULong \
			binds to "objc:EventKit>EKEventstore.-authorizationStatusForEntityType:"
The is being called by this line :

Code: Select all

put ObjC_EKEventStoreAuthStatus(sEventStore, 0) into tAuthorisationCode
sEventstore is declared with

Code: Select all

private variable sEventStore as optional ObjcObject
and tAuthorisationCode with

Code: Select all

variable tAuthorisationCode as optional Integer
sEventstore has been set to an EKEventstore object using calls to "alloc" and "init". If is tested as not nothing before the call to ObjC_EKEventStoreAuthStatus is made. The first time I initialised sEventstore I was prompted to provide permission so I believe that the creation of the object was successful.

I have been plugging away at this one call for most of the day and do not what else to try. Any thoughts?
best wishes
Skids

Simon Knight
Posts: 845
Joined: Wed Nov 04, 2009 11:41 am
Location: Gunthorpe, North Lincs, UK

Re: Error : Unable to bind foreign handler

Post by Simon Knight » Sun Feb 09, 2020 4:02 pm

Answering my own question. The definition that works is like this:

Code: Select all

private foreign handler ObjC_EKEventStoreAuthStatus(in pEKEntityMaskEvent as CUint) \
			returns CULong \
			binds to "objc:EventKit>EKEventStore.+authorizationStatusForEntityType:"
The key is that the method is a class method and not an instance method. So the reference to the instance has to be removed from from the parameters and the prefix to the method changed from a "-" to a "+".

Moral of the storey : Read the documentation, then read it a again.
best wishes
Skids

Post Reply

Return to “LiveCode Builder”