iOS Question How to pass data to inline objective C

Jack Cole

Well-Known Member
Licensed User
Longtime User
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.

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:



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!
 

Jack Cole

Well-Known Member
Licensed User
Longtime User
Solved it. It was actually related using LogColor in the Main_ShouldAutoRotate sub. I use a custom class that contains many colors, and this was firing before that class was initialized. For some reason, that was not referenced in the crash. Thank you for prompting me to make a small example.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…