supported InterfaceOrientations iOS 8 vs. iOS 9

Hi,


i need in my App following Code:

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;

}


this works fine in iOS 8.


but in iOS 9 (Xcode 7) i became a warning:

"Conflicting return type in implementation of 'supportedInterfaceOrientations': 'UIInterfaceOrientationMask' (aka 'enum UIInterfaceOrientationMask') vs 'NSUInteger' (aka 'unsigned long')"


i have changed it to:

-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

and have fixed this Warning. But now i became a Warning in Xcode 6.3 (iOS 8)


How can i make this Code compatible for iOS 9 AND iOS 7 / 8 ?



Thanks, Tweak

Accepted Reply

I personally prefer this way:


#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif

Replies

The typical way to bifurcate based on iOS version is via idioms.

Example is for Swift:

to detect iOS version

struct Version{ static let SYS_VERSION_FLOAT = (UIDevice.currentDevice().systemVersion as NSString).floatValue static let iOS7 = (Version.SYS_VERSION_FLOAT < 8.0 && Version.SYS_VERSION_FLOAT >= 7.0) static let iOS8 = (Version.SYS_VERSION_FLOAT >= 8.0 && Version.SYS_VERSION_FLOAT < 9.0) static let iOS9 = (Version.SYS_VERSION_FLOAT >= 9.0 && Version.SYS_VERSION_FLOAT < 10.0) }

how to use

if Version.iOS8 { println("iOS8") }

I don't think there is a way in Swift for you to support both from a compilation stand point. Just like with other changes for Swift 2, Xcode 7, and iOS 9, I would recommend you make these changes on a branch in your code repository such that it won't interfere with your changes when working with Swift 1.2, Xcode 6.3 and iOS 8.3.

i use Objective-C and don't know, how can i make the code available for iOS9 and iOS 8. the "old" code does not run under iOS 9 and the new dont rund under iOS 8... iam not professional and need a idea :-)

I think you are misunderstanding. The old code will run fine under iOS 8 or 9, and the new code will also run fine under iOS 8 or 9.


The old syntax won't *compile* when built using Xcode 7 and the iOS 9 *SDK*. Likewise the new syntax won't *compile* using Xcode 6 and the iOS 8 SDK. But a binary built using either tool will run on whatever OS it's targeted for.


If you're not planning to release until this fall, after Xcode 7 / iOS 9 goes public, then just use the new syntax and Xcode 7 and don't worry about it. If you need to release sooner, use Xcode 6 and the old syntax and don't worry about it. There's not much point trying to make code that compiles under either. You'd need some conditional compilation directives and it would get messy. Better to just use a branch, as Rincewind suggested, if you absolutely have to have code that compiles against both SDK versions.

just use this one:


#pragma clang diagnostic push

#pragma clang diagnostic ignored "-Woverriding-method-mismatch"

#pragma clang diagnostic ignored "-Wmismatched-return-types"

- (UIInterfaceOrientationMask)supportedInterfaceOrientations

#pragma clang diagnostic pop

I personally prefer this way:


#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif