I have just spent the day trying to add "authorisation" to my Calendar Event library. I believe that this is required if it is to be of any use on iOS. The objective C is described https://developer.apple.com/documentati ... guage=objc
The objective-c method is
Code: Select all
- (void)requestAccessToEntityType:(EKEntityType)entityType
completion:(EKEventStoreRequestAccessCompletionHandler)completion;
Code: Select all
entityType
The event or reminder entity type.
completion
The block to call when the request completes.
Code: Select all
CreateObjcBlockPointerFromHandler(pHandler,rBlockPtr)
The dictionary includes an example posted below and I would like some help to work out what is happening:
Code: Select all
private variable sRequestPermissionsCompletionHandler as optional ObjcBlockPointer
private variable sTarget as ScriptObject
public handler AudioLibraryInitialize() returns Boolean
if not CreateObjcBlockPointerFromHandler(RequestPermissionsCompletionHandler, sRequestPermissionsCompletionHandler) then
put nothing into sRequestPermissionsCompletionHandler
return false
end if
put the caller into sTarget
return true
end handler
private foreign handler ObjC_AVCaptureDeviceRequestAccessForMediaType(in pMediaType as ObjcId, in pCompletionHandler as ObjcBlockPointer) \
returns nothing \
binds to "objc:AVCaptureDevice.+requestAccessForMediaType:completionHandler:"
public handler AudioLibraryRequestPermissions()
unsafe
ObjC_AVCaptureDeviceRequestAccessForMediaType(StringToNSString("soun"), sRequestPermissionsCompletionHandler)
end unsafe
end handler
public handler RequestPermissionsCompletionHandler(in pBlock as ObjcBlockPointer, in pGranted as CBool)
post "AudioLibraryRequestPermissionsCallback" to sTarget with [pGranted]
end handler
My thoughts so far :
The aim is to enable the LCB library to use the class method +requestAccessForMediaType:completionHandler: which is a method of the AVCaptureDevice class. The complication is that the completionHandler requires a pointer to a block of code (a handler?) that is called once the method completes (true/false/other)?
So to create this block pointer the public handler AudioLibraryInitalise has to be called first and this creates the block pointer and stores it in the ObjcBlockPointer variable sRequestPermissionsCompletionHandler. It also puts 'the caller' into a variable scriptobject sTarget. I think that sTarget refers to the LCB script (true/false/other)?
The handler AudioLibraryRequestPermissions() calls the Objc class method defined in the private foreign handler. This does whatever it does and on completion calls the final handler RequestPermissionsCompletionHandler as this is what is being pointed at in the block pointer. This posts the text to sTarget, which might be the LCB script, along with pGranted which is type CBoolean. (true/false/other)?
Where did pGranted originate given that the objC foreign handler returns nothing?
best wishes from confused of North Lincolnshire
Simon