Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to hide code based on SDK version

Because my build machine is still using the Xcode 12.5 , So the UITabBar's scrollEdgeAppearance(which will not exist in the Xcode 12.5's SDK) will make the build fail even i'am using the @available to check .

if (@available(iOS 15.0, *)) {
    UINavigationBarAppearance* navBarAppearance = [UINavigationBarAppearance new];
    navBarAppearance.backgroundColor = [UIColor colorNamed:@"navbar_bg"];

    [UINavigationBar appearance].standardAppearance = navBarAppearance;
    [UINavigationBar appearance].scrollEdgeAppearance = navBarAppearance;
    
    UITabBarAppearance* tabBarAppearance = [UITabBarAppearance new];
    tabBarAppearance.backgroundColor = [UIColor colorNamed:@"second_bg"];
    [UITabBar appearance].standardAppearance = tabBarAppearance;
    [UITabBar appearance].scrollEdgeAppearance = tabBarAppearance;
    
    [UITableView appearance].sectionHeaderTopPadding = 0;
}

So is it possible to do this kind of SDK checking in code ,when the build SDK is not the newest SDK , these code will not be involved to build? like this

if (BuilDSDK >= someversion) 
{
   [UITabBar appearance].scrollEdgeAppearance = tabBarAppearance;
}
like image 597
ximmyxiao Avatar asked Aug 16 '21 06:08

ximmyxiao


People also ask

How can I hide my source code?

This is by far the most popular way to try to hide one’s source code. It involves taking your code, using a custom made function to “encrypt” it somehow, and then putting it in an HTML file along with a function that will decrypt it for the browser. A User is able to view the source, however, it isn’t understandable.

What is SDK in software development?

It’s a set of software tools and programs used by developers to create applications for specific platforms. SDK tools will include a range of things, including libraries, documentation, code samples, processes, and guides that developers can use and integrate into their own apps.

What is the difference between SDK and API?

In this case, go back to the SDK meaning: it’s a development kit. The SDK can contain one or more APIs plus essential utilities. The API is just one part of an SDK. Think of the devkit as a larger “container” for an entire array of SDK tools and you’ll be correct.

How to hide the JavaScript source code in cleartext?

Well, long story short – It is impossible to hide the Javascript source code, as it is downloaded into the client computer in cleartext. But there are still ways to make it difficult to decipher the code: Obfuscate the Javascript. Disable right-click on the pages. Disable view source shortcut keys.


Video Answer


2 Answers

@available is a runtime availability check, not really usable for compile-time stuff in this situation.

In Objective-C, you can wrap the code part applied on iOS 15 SDK into another, macro condition:

#ifdef __IPHONE_15_0
    if (@available(iOS 15.0, *)) {
        ...
    } else {
#endif
        // possible legacy branch code
#ifdef __IPHONE_15_0
    }
#endif

__IPHONE_15_0 is defined starting with iOS 15 SDK, thus being omitted when building in Xcode 12/iOS 14 SDK. đź‘Ť

like image 65
Michi Avatar answered Nov 15 '22 08:11

Michi


Another similar solution for Swift classes can be found here: https://stackoverflow.com/a/69583441/1195661:

#if swift(>=5.5) // Only run on Xcode version >= 13 (Swift 5.5 was shipped first with Xcode 13).
        if #available(iOS 15.0, *) {
            UITabBar.appearance().scrollEdgeAppearance = tabBarAppearance
        }
#endif
like image 30
palme Avatar answered Nov 15 '22 09:11

palme