iOS Question Objective C help needed in attempt to get selective rotation in iOS 16+ working

JackKirk

Well-Known Member
Licensed User
Longtime User
I'm trying to update:

https://www.b4x.com/android/forum/t...essentially-portrait-only-app.104006/#content

to work on iOS 16+

I have spent the weekend playing with OBJC - and I know little - and would like to know less - which is what B4i is about.

Experimenting, I have the following embellished OBJC:
Objective-C:
#if OBJC
@end
@interface UIViewController (B4IResize)

@end
@implementation UIViewController (B4IResize)

-(BOOL)shouldAutorotate
{
  return [(NSNumber*)[B4IObjectWrapper raiseEvent:self :@"_shouldautorotate" :nil] boolValue];
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
//https://developer.apple.com/documentation/uikit/uiinterfaceorientationmask/uiinterfaceorientationmaskportrait?language=objc
//return UIInterfaceOrientationMaskPortrait;
  return 1;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//https://developer.apple.com/documentation/uikit/uiinterfaceorientation/portrait
  return 1;
}

//setNeedsUpdateOfSupportedInterfaceOrientations()

#End If
B4X:
-(BOOL)shouldAutorotate
{
  return [(NSNumber*)[B4IObjectWrapper raiseEvent:self :@"_shouldautorotate" :nil] boolValue];
}
is just the original OBJC from the above referenced post - this works as before.
B4X:
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
//https://developer.apple.com/documentation/uikit/uiinterfaceorientationmask/uiinterfaceorientationmaskportrait?language=objc
//return UIInterfaceOrientationMaskPortrait;
  return 1;
}

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
//https://developer.apple.com/documentation/uikit/uiinterfaceorientation/portrait
  return 1;
}
is new code that seems to compile OK - when I get the final step working I will come back and attempt to generalize the "portrait" parameter
B4X:
//setNeedsUpdateOfSupportedInterfaceOrientations()

This bit has me stumped - I've tried every permutation I can think of.

It is supposed to tell the view controller to update with respect to the "portrait" settings I have made in the prior steps.

Any Objective C help to get this to compile OK would be really appreciated...
 

Filippo

Expert
Licensed User
Longtime User
Hi @JackKirk ,

I use the pageOrientations module pageOrientations in my app and my solution looks like this:
B4X:
Sub pMain_Appear
'    Log("pMain_Appear")

    If App.OSVersion < 16 Then
        pageOrientations.setInterfaceOrientations (pMain, "Portrait")
    Else
        SetSupportedOrientation(ORIENTATION_PORTRAIT)
    End If
End Sub
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I use the pageOrientations module pageOrientations in my app and my solution looks like this:
Hi Filippo - I have been seeing your name crop up all around this problem - we share joy in finally having an iOS 16+ solution.

I have successfully incorporated Erels new iOS 16+ and my old pre iOS 16+ solution into my major iOS app and have tested it on iOS 15.8.1 (my iPhone 7) and iOS 17.3.1 (AWS Device Farm iPhone 15) and it all works seamlessly - I expect to have it published overnight and am pleased as punch.
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
I expect to have it published overnight and am pleased as punch.
Today I have already published 2 applications with the new routine. :)
I tested on iPhone-6+(iOS 12.5.7) , iPhone-X(iOS 16.7.5) and iPad-Mini(iOS 17.2).
 
Upvote 0
Top