iOS在不同版本的代码中运行代码

时间:2016-10-02 19:36:57

标签: ios conditional

我是iOS新手。在我们的一个iOS应用程序中,我需要在iOS版本中执行function1 => 9和功能2到iOS版本< 9.以下代码是否适用于此方案?

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    // when the app is opened due to a deep link, call the Tune deep link setter
    [Tune applicationDidOpenURL:url.absoluteString sourceApplication:sourceApplication];

    return YES;
}
#endif

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 90000
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options
{
    // when the app is opened due to a deep link, call the Tune deep link setter
    NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];

    [Tune applicationDidOpenURL:url.absoluteString sourceApplication:sourceApplication];

    return YES;
}
#endif

1 个答案:

答案 0 :(得分:0)

请尝试this link

但改变功能:&#34; isOperatingSystemAtLeastVersion&#34;如果有的话。

if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){.majorVersion = 9, .minorVersion = 1, .patchVersion = 0}]) {
    NSLog(@"Hello from > iOS 9.1");
}

// Using short-form for the struct, we can make things somewhat more compact:
if ([NSProcessInfo.processInfo isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){9,3,0}]) {
    NSLog(@"Hello from > iOS 9.3");
}