UIAlertController if iOS 8, otherwise UIAlertView

后端 未结 11 2040
清酒与你
清酒与你 2020-12-16 10:19

I want to conform to the UIAlertController used in iOS 8 since UIAlertView is now deprecated. Is there a way that I can use this without breaking support for iOS 7? Is there

11条回答
  •  渐次进展
    2020-12-16 10:38

    Method one

    by ios system version check

    #define iOSVersionLessThan(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
    // below ios8 ,create UIAlertView
    if(iOSVersionLessThan(@"7.0")){
         // todo
    
    // ios8 and above ,UIActionController avaliable
    }else{
        // todo
    }
    

    Method two

    by system feature detect

    // create UIActionController 
    if([UIActionController class]){
        // todo
    // create UIAlertView
    }else{
        // todo
    }
    

    But,there's a third lib named PSTAlertController that deal with backwards compatible to iOS 7 of UIActionSheet and UIAlertView.

    ref to

    • Supporting Multiple Versions of iOS
    • Supporting iOS 6
    • Supporting Multiple iOS Versions and Devices

提交回复
热议问题