I am trying to alter some inline Objective C code to handle programmatically preventing orientation change (the original code crashes on startup in release mode. but works in debug mode). The problem is related to views/variables not being ready. What I want to do is to set a variable when the views become available after launch. I can't pass this data as a parameter, because the original sub is called as an event.
I can see some solutions, but I could not find examples in the forum.
Here are possibilities. I have searched the forums, but was unable to find any examples. If you know of any examples of how to do any of the following, that would solve my problem.
1). Run an Objective C sub (called from b4i) to set a global variable accessible to the inline code. I try to do this in the example below, but it crashes.
2). Access a global variable in the b4i module from the Objective C code.
3). Call a B4i sub from the Objective C code and return true or false if the views are ready. I can see how to call a sub, but could not find any examples of returning a value with a b4i sub.
It crashes with the following error:
If anyone has any examples of how to do any one of the 3 possibilities I referenced above, it would be greatly appreciated. Thank you!
I can see some solutions, but I could not find examples in the forum.
Here are possibilities. I have searched the forums, but was unable to find any examples. If you know of any examples of how to do any of the following, that would solve my problem.
1). Run an Objective C sub (called from b4i) to set a global variable accessible to the inline code. I try to do this in the example below, but it crashes.
2). Access a global variable in the b4i module from the Objective C code.
3). Call a B4i sub from the Objective C code and return true or false if the views are ready. I can see how to call a sub, but could not find any examples of returning a value with a b4i sub.
B4X:
Sub SetViewsReady
Dim NativeMe As NativeObject = Me
NativeMe.RunMethod("enableRotationCheck:", Null)
' NativeMe.SetField("enableCheck", True)
End Sub
#if OBJC
@end
@interface UINavigationController (B4IResize)
@end
@implementation UINavigationController (B4IResize)
BOOL enableCheck=NO;
- (BOOL)shouldAutorotate
{
if (enableCheck) {
return [(NSNumber*)[B4IObjectWrapper raiseEvent:self :@"_shouldautorotate" :nil] boolValue];
} else {
return YES;
}
}
- (void)enableRotationCheck {
NSLog(@"enableRotationCheck");
enableCheck=YES;
}
#End If
It crashes with the following error:
Error occurred on line: 247 (Main)
Method not found: enableRotationCheck:, target: <b4i_main: (null)>
Stack Trace: (
CoreFoundation __exceptionPreprocess + 242
libobjc.A.dylib objc_exception_throw + 48
CoreFoundation -[NSException initWithCoder:] + 0
Minesweeper +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 342
Minesweeper -[B4INativeObject RunMethod::] + 219
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 305
Minesweeper +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
Minesweeper -[B4IShell runVoidMethod] + 184
Minesweeper -[B4IShell raiseEventImpl:method:args::] + 1699
Minesweeper -[B4IShellBI raiseEvent:eventarams:] + 1358
Minesweeper +[B4IDebug delegate:::] + 66
Minesweeper -[b4i_main _setviewsready] + 155
Minesweeper -[ResumableSub_b4xmainpage_UI_Restore_State resume::] + 2468
Minesweeper -[b4i_b4xmainpage _ui_restore_state::] + 473
Minesweeper -[ResumableSub_b4xmainpage_UI_Create resume::] + 5103
CoreFoundation __invoking___ + 140
CoreFoundation -[NSInvocation invoke] + 305
Minesweeper +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 1519
Minesweeper -[B4IShell runMethod:] + 380
Minesweeper -[B4IShell raiseEventImpl:method:args::] + 2076
Minesweeper -[B4IShellBI raiseEvent:eventarams:] + 1358
Minesweeper -[B4IDelegatableResumableSub resume::] + 375
If anyone has any examples of how to do any one of the 3 possibilities I referenced above, it would be greatly appreciated. Thank you!