C stuff, getting a bit lost with it having coming from LUA. I've programmed for years but not sure how to store my delegate object and point to it later. I'm able to create a new instances fine but need to reference a previously created instance from a Corona Enterprise plugin for iOS. Hopefully someone can help past this small issue.
So I define a variable after my CoronaIbeaconDelegate @interface like so:
CoronaIBeaconDelegate *coronaIBeaconDelegate;
Later on in my Corona Plugin class code I create a instance of CoronaIBeaconDelegate like so:
int
PluginLibrary::scan( lua_State *L )
{
int listenerIndex = 1;
coronaIBeaconDelegate = [[CoronaIBeaconDelegate alloc] firstRegion];
if ( CoronaLuaIsListener( L, listenerIndex, kEvent ) )
{
Self *library = ToLibrary( L );
CoronaLuaRef listener = CoronaLuaNewRef( L, listenerIndex );
library->Initialize( listener );
// Create event and add message to it
CoronaLuaNewEvent( L, kEvent );
lua_pushstring(L,"scan");
lua_setfield(L, -2, "phase" );
lua_pushboolean(L,true );
lua_setfield(L, -2, "scanning" );
lua_pushstring( L, "Scanning Started" );
lua_setfield( L, -2, "message" );
// Dispatch event to library's listener
CoronaLuaDispatchEvent( L, library->GetListener(), 0 );
}
return 0;
}
This will work fine but I get a warning when storing the delegate in coronaIBeaconDelegate variable saying "instance method not found -firstRegion" but this will call the class function firstRegion fine as expected and my IBeacon code starts scanning.
What I want to do is be able to call another function in the CoronaIBeaconDelegate class called stopRangingForBeacons likes so using the previous instance:
int
PluginLibrary::stopscan( lua_State *L )
{
int listenerIndex = 1;
[coronaIBeaconDelegate stopRangingForBeacons];
if ( CoronaLuaIsListener( L, listenerIndex, kEvent ) )
{
Self *library = ToLibrary( L );
CoronaLuaRef listener = CoronaLuaNewRef( L, listenerIndex );
library->Initialize( listener );
// Create event and add message to it
CoronaLuaNewEvent( L, kEvent );
lua_pushstring(L,"stopscan");
lua_setfield(L, -2, "phase" );
lua_pushboolean(L,true );
lua_setfield(L, -2, "scanning" );
lua_pushstring( L, "Scanning Stopped" );
lua_setfield( L, -2, "message" );
// Dispatch event to library's listener
CoronaLuaDispatchEvent( L, library->GetListener(), 0 );
}
return 0;
}
Whats occurs is a null error. I tried to store the previous instance in the coronaIBeacon variable but it doesn't work. I really can't seem to suss this simple task.
Please help thanks?
As per usual I answer my own question. My issue was due to the way I was initialising my instance. Here is the correct way in my case.
IBeaconDelegate = [[CoronaIBeaconDelegate alloc] init];
[IBeaconDelegate firstRegion];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.