Satyam Satyam - 8 days ago 7
iOS Question

iOS app in portrait & landscape only for iPhone 6+/7+

How can I set my project configuration to allow my app to work in both portrait and landscape on iPhone 6+ & 7+ models and other iPhone models has to support only Portrait?

Answer

use this third party lib for detecting the running device's model and screen size.

//AppDelegate.h

@property () BOOL restrictRotation;

//AppDelegate.m

import "AppDelegate.h"

import "SDVersion.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

 // Check for device model
if ([SDiOSVersion deviceVersion] == iPhone7Plus){
    NSLog(@"You got the iPhone 7. Nice!");
  restrictRotation=YES;
}
else if ([SDiOSVersion deviceVersion] == iPhone6SPlus){
    NSLog(@"You got the iPhone 6S Plus. Awesome device!");
   restrictRotation=YES;
}


 return YES;
}

-(UIInterfaceOrientationMask )application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if(self.restrictRotation)
    {
        return UIInterfaceOrientationMaskPortrait;
    }
    else
    {
       return UIInterfaceOrientationMaskAll;
    }

}
Comments