I'm trying to get a rise event call from objective C to a b4i sub
This works:
B4X:
Sub nsdata_sub(x As NativeObject)
Dim NSS As String = x
end sub
#If ObjC
- (void)test{
uint8_t bytes[] = {1,2,3,6,7,8,11,12,13};
NSData *data = [NSData dataWithBytes:bytes length:sizeof(bytes)];
[self.bi raiseUIEvent:nil event:@"nsdata_sub:" params:@[data]];
}
#end if
However, trying the same within the implementation of a class, doesnt
Your code cannot work. There is no relation between the B4INFC class code and any other class instance.
Working example:
B4X:
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private Panel1 As B4XView
Private nfc As NativeObject
End Sub
Public Sub Initialize
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
nfc = nfc.Initialize("B4INFC").RunMethod("new", Null)
nfc.RunMethod("initialize:", Array(Me))
End Sub
Private Sub Button1_Click
nfc.RunMethod("test", Null)
End Sub
Private Sub NSData_Sub(Data As Object)
Log(Sender & ": " & Data)
End Sub
#if OBJC
@end
#import...
Your code cannot work. There is no relation between the B4INFC class code and any other class instance.
Working example:
B4X:
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private Panel1 As B4XView
Private nfc As NativeObject
End Sub
Public Sub Initialize
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
nfc = nfc.Initialize("B4INFC").RunMethod("new", Null)
nfc.RunMethod("initialize:", Array(Me))
End Sub
Private Sub Button1_Click
nfc.RunMethod("test", Null)
End Sub
Private Sub NSData_Sub(Data As Object)
Log(Sender & ": " & Data)
End Sub
#if OBJC
@end
#import <Foundation/Foundation.h>
#import <CoreNFC/CoreNFC.h>
typedef void(^CompletionHandler)(NSError *error);
@interface B4INFC:NSObject <NFCTagReaderSessionDelegate>
@end
@implementation B4INFC {
B4I* bi;
}
- (void)initialize:(B4IClass*) me {
self->bi = me.bi;
}
- (void)test{
NSData *data = nil;
[self->bi raiseUIEvent:self event:@"nsdata_sub:" params:@[[B4I nilToNSNull:data]]];
}
#End If