[SDK] UIInterfaceOrientationMask

In MyAppDelegate.m

@interface MyAppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate>
{
    NSInteger skipforeground;
    BOOL allowLandscape;
    NSInteger NoCheck;
}

- (UIInterfaceOrientationMask)application:(UIApplication *) application
  supportedInterfaceOrientationsForWindow:(UIWindow *) window {
    
    if (self->allowLandscape==true) {
        NSLog(@"rotation yes !");
        return UIInterfaceOrientationMaskAll;
    } else
    {
        return UIInterfaceOrientationMaskPortrait;
    };
    
}


-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{

//Called when a notification is delivered to a foreground app.
     
    NSString *Param=notification.request.content.userInfo[@"scriptParam"];
    if ([Param isEqual:@"TurnOffRotation"]) {
        self->allowLandscape=false;
    }

} else if ([Param isEqual:@"TurnOnRotation"]) {
       self->allowLandscape=true;    
    }

In Filemaker

Configure Local Notification [ Action: Queue ; Name: "RunFunction" ; Script: “EmptyScript” ; Parameter: "TurnOnRotation"; Delay: 0 ] 

The code above was used to unlock or lock landscape orientation depending on the layout .

It stopped working for some reason.

The condition is met and I see "rotation yes !" in the log but the screen won't rotate.
If I change the condition for an always true condition like "2>1" the screen will rotate.
As soon as I reference self->allowLandscape in supportedInterfaceOrientationsForWindow the code is executed but the screen does not rotate.

Anyone knows how to fix it ?

1 Like

Hi @sfpx, interesting problem. I'll tag @bhamm. He's got a lot of experience with Swift and FileMaker.

2 Likes

Welcome to Thesoup @sfpx !

Thanks.
Anyone has any idea what could cause this ?
This is so strange to me.

Finally was able to get it to work (IOS 16+ only) by adding this

 if (@available(iOS 16.0, *)) {
            [UIApplication sharedApplication].keyWindow.rootViewController.setNeedsUpdateOfSupportedInterfaceOrientations;
        }

after each time I change allowLandscape

For example

...
else if ([Param isEqual:@"TurnOnRotation"]) {
       self->allowLandscape=1;
 if (@available(iOS 16.0, *)) {
            [UIApplication sharedApplication].keyWindow.rootViewController.setNeedsUpdateOfSupportedInterfaceOrientations;
        };
}
...
1 Like