Conflicting return type in implementation of 'supportedInterfaceOrientations': - Warning
IosObjective CXcodeIos Problem Overview
After upgrading to Xcode 7.0 I get a warning in the UIViewControllerRotation method: - (NSUInteger)supportedInterfaceOrientations
:
> Conflicting return type in implementation of > 'supportedInterfaceOrientations': 'UIInterfaceOrientationMask' (aka > 'enum UIInterfaceOrientationMask') vs 'NSUInteger' (aka 'unsigned > int')
Why is that, and how do I fix it?
EDIT:
If you go to the definition you'll see that the return type acctually has changed:
- (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
but changing the return type in the code doesn't silence the warning.
Ios Solutions
Solution 1 - Ios
Try this tweak:
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
return UIInterfaceOrientationMaskPortrait;
}
Solution 2 - Ios
I am using this one:
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0
#define supportedInterfaceOrientationsReturnType NSUInteger
#else
#define supportedInterfaceOrientationsReturnType UIInterfaceOrientationMask
#endif
- (supportedInterfaceOrientationsReturnType)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
... a little bit longer than Nishant's fix but a little bit clearer, I think.
Solution 3 - Ios
I have been at this for a few weekends to figure out the proper solution, I have tried many others solutions but just did not work properly. If you want only certain UI to be in landscape or Portrait try this method below. I am running Xcode 7.2.1 , I am using a Bool to set the value along with NSUSerDefaults in each Class I want to follow specific UIInterfaceOrientations.The method below gets called each time there is a new UI presented or when the device is rotated , you could check this by putting a NSLog checking the value of the bool in that method and see for yourself how it changes.
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:
In you AppDelegate do the following
.h @property (assign, nonatomic) BOOL shouldRotate;
.m
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED{
_shouldRotate = [[NSUserDefaults standardUserDefaults]boolForKey:@"rotateKey"];
NSLog(@"Did I get to InterfaceOrientation \n And the Bool is %d",_shouldRotate);
if (self.shouldRotate == YES)
return UIInterfaceOrientationMaskAllButUpsideDown;
else
return UIInterfaceOrientationMaskPortrait;
}
NOW IN EVERY CLASS YOU WANT TO HAVE A SPECIFIC UIINTERFACEORIENTATION DO THIS
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
// [[AppDelegate sharedAppDel]setShouldRotate:YES];
BOOL rotate = NO;
[[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"];
[[NSUserDefaults standardUserDefaults]synchronize];
}
-(BOOL)shouldAutorotate
{
return YES;
}
In the Views you want to rotate change the Bool value to Yes. Now in your AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
BOOL rotate = NO;
[[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"];
[[NSUserDefaults standardUserDefaults]synchronize];
return YES;
}
Also in your AppDelegate
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
BOOL rotate = NO;
[[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"];
[[NSUserDefaults standardUserDefaults]synchronize];
}
Hope this helps many developers. Tested and Tested many times.
Regards
JZ