Share Sheet and Orientation on iPad

Hello there!

I have implemented a share function using OBJ-C Swift Bridge. Functionally it works, but I always get in a muddle with ViewControllers etc and I’m having issues with the orientation of the Share Sheet. It always presents portrait in this landscape only app, it also doesn’t respond to the rotation of the device.

Here is the code:

import UIKit
import Foundation

@objc public class ShareSheet: UIViewController{
    var topVC = UIViewController()
    var orientation : UIInterfaceOrientationMask = .landscape
    @objc public func shareFile(_ filePathToShare: String){
        let fileP = NSURL(fileURLWithPath: filePathToShare)
        presentShareSheet(fileURL: fileP)
    func presentShareSheet(fileURL: NSURL){
        // Create the Array which includes the files you want to share
        var filesToShare = [Any]()

        // Add the path of the file to the Array
        topVC = topMostController()
        // Make the activityViewContoller which shows the share-view
        let activityViewController = UIActivityViewController(activityItems: filesToShare, applicationActivities: nil)
        activityViewController.modalPresentationStyle = .popover
        activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.midX, height: UIScreen.main.bounds.midY)
        activityViewController.popoverPresentationController?.sourceView = topVC.view
        topVC.present(activityViewController, animated: true, completion: nil)
    func topMostController() -> UIViewController {
        var topController: UIViewController = UIApplication.shared.keyWindow!.rootViewController!
            while (topController.presentedViewController != nil) {
                topController = topController.presentedViewController!
            return topController

I am also experiencing the issue (which I had managed to solve at some point many moons and many versions ago, but that fix doesn’t work now) with orientation on startup.
This is a landscape only iPad app, in the project settings it is set as landscape only, but when it boots it presents 90’ out, the touch positions are correct to the hardware, but the drawn view is 90’ out. This gets resolved if the user rotates the device, after that it locks into landscape only and behaves as expected, I have set “settings.setupOrientation = OF_ORIENTATION_90_LEFT;” in the main.cpp. I have also tried the below in ofApp setup, I have also tried it in the first frame of update too, but it hasn’t worked:

ofxiOSGetGLView().frame = CGRectMake(0,0,[[UIScreen mainScreen]bounds].size.width,[[UIScreen mainScreen] bounds].size.height);
if(ofxiOSGetGLView().frame.origin.x != 0
    || ofxiOSGetGLView().frame.size.width != [[UIScreen mainScreen] bounds].size.width){

        ofxiOSGetGLView().frame = CGRectMake(0,0,[[UIScreen mainScreen] bounds].size.width,[[UIScreen mainScreen] bounds].size.height);

I’m not sure if these issues are connected or not, but at the least the topic is vaguely the same!