UIAlertController if iOS 8, otherwise UIAlertView

后端 未结 11 2037
清酒与你
清酒与你 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:53

    Create simple utility function to reduce code

    CODE :

    // pass minimum required iOS version
    BOOL isOSSupported(NSString *minRequiredVersion)
    {
        NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
        BOOL isOSSupported = ([currSysVer compare:minRequiredVersion options:NSNumericSearch] != NSOrderedAscending) && 
                                      ![currSysVer isEqualToString:@"Unknown"];
        return isOSSupported;
    }
    


    USE :

    if(isOSSupported("8.0")
    {
    // Code for iOS8 and above
    }
    else
    {
    // Code for iOS7 and below
    }
    



    Or Use system constant NSFoundationVersionNumber_iOS_7_1 as below

    if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
    {
       // Code for iOS8 and above
    }
    else
    {
       // Code for iOS7 and below
    }
    


    for more options Link

提交回复
热议问题