Note: The stream ingest SDK for iOS rotates the collected video frames instead of the player view. To use the stream ingest SDK for iOS to ingest a stream in the landscape mode, you must lock the portrait display in the controller code.

If you need to ingest a stream in the landscape mode, develop an adaptation plan that fits the landscape mode of the UI. In this adaptation plan, the preview view does not need to be rotated. For example, if the preview view is in full-screen, you do not need to modify the preview view in the landscape mode, except that you can adjust the frames of buttons such as the Like button.

Procedure

  1. Detect the display orientation of the device.

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDeviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
                        
  2. Set the landscape or portrait mode for stream ingest in the handleDeviceOrientationDidChange callback.

    - (void)handleDeviceOrientationDidChange:   (UIInterfaceOrientation)interfaceOrientation {
    
     UIDevice *device = [UIDevice currentDevice] ;
     switch (device.orientation) {
         case UIDeviceOrientationFaceUp:
             NSLog(@"Screen up");
             break;
    
         case UIDeviceOrientationFaceDown:
             NSLog(@"Screen down");
             break;
    
         case UIDeviceOrientationUnknown:
             NSLog(@"Unknown");
             break;
    
         case UIDeviceOrientationLandscapeLeft: {
             NSLog(@"Left side down");
             // Ingest a stream in the landscape mode.
             [self destroySession];     // Interrupt the current stream ingest.
             // We recommend that you add a loading method here. If you interrupt and then resume the current stream ingest, the system disables and then enables the camera to collect a stream.
             _isScreenHorizontal = YES;  // Specify whether to use the portrait mode or landscape mode. To use the landscape mode, set this parameter to YES.
             [self testPushCapture];    // Re-ingest a stream.
         }
             break;
    
         case UIDeviceOrientationLandscapeRight:
             NSLog(@"Right side down");
             break;
    
         case UIDeviceOrientationPortrait: {
             NSLog(@"Portrait");
             // Ingest a stream in the portrait mode.
             [self destroySession];     // Interrupt the current stream ingest.
             _isScreenHorizontal = NO;  // Specify whether to use the portrait mode or landscape mode. To use the landscape mode, set this parameter to NO.
             [self testPushCapture];    // Re-ingest a stream.
         }
             break;
    
         case UIDeviceOrientationPortraitUpsideDown:
             NSLog(@"Portrait with upside down");
             break;
    
         default:
             NSLog(@"Unknown");
             break;
     }
    
    }
                        
  3. Log off from the device.

    - (void)dealloc{
     [[NSNotificationCenter defaultCenter] removeObserver:self];
     [[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications];
    }