//
//  UIDevice+YsSaas.m
//  EZSaaSVideoConferenceSDK
//
//  Created by li yue on 2020/1/29.
//  Copyright © 2020 EZSaaS. All rights reserved.
//

#import "UIDevice+YsSaas.h"

@implementation UIDevice (YsSaas)

+ (void)ys_setOrientation:(UIInterfaceOrientation)orientation
{
    //iOS10.3以上存在问题：设备方向与旋转的方向一致时，不会触发旋转；先旋转到状态栏方向来进行过度（TD32270）
    UIInterfaceOrientation deviceOri = (UIInterfaceOrientation)[UIDevice currentDevice].orientation;
    UIInterfaceOrientation statusBarOri = [UIApplication sharedApplication].statusBarOrientation;
    if (deviceOri == orientation && statusBarOri != deviceOri) {
        NSLog(@"ys_setOrientation statusBarOri:%d", (int)statusBarOri);
        [UIDevice private_setDeviceOrientation:statusBarOri];
    }
    
    [UIDevice private_setDeviceOrientation:orientation];
}

+ (void)private_setDeviceOrientation:(UIInterfaceOrientation)orientation
{
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
    {
        SEL selector = NSSelectorFromString(@"setOrientation:");
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
        [invocation setSelector:selector];
        [invocation setTarget:[UIDevice currentDevice]];
        [invocation setArgument:&orientation atIndex:2];
        [invocation invoke];
    }
}

//如果想要判断设备是ipad，要用如下方法
+ (BOOL)getIsIpad
{
    NSString *deviceType = [UIDevice currentDevice].model;
    if([deviceType isEqualToString:@"iPhone"]) {
        //iPhone
        return NO;
    }
    else if([deviceType isEqualToString:@"iPod touch"]) {
        //iPod Touch
        return NO;
    }
    else if([deviceType isEqualToString:@"iPad"]) {
        //iPad
        return YES;
    }
    
    return NO;
}

@end
