What is a good approach to disable features that are not supported?

I assume this question is agnostic because I ask it regarding the creation of an iPhone application that uses the new Game Center API, but please do not hesitate to respond to the general terms of software development.

I am creating a game for the iPhone that uses the new features of Game Center (i.e. Auto-matching, leaderboards, achievements, etc.), but I want to write the game so that it works on all iPhones, including those that don’t have Game Center, and cannot use the capabilities of Game Center. For this, Apple recommends an approach ...

"We would recommend making one version of the application that dynamically detects whether Game Center is available and uses it (or not) based on this."

With my current programming level, the simple approach I would take to implement this would be to check if Game Center is available or not, and set a simple boolean flag accordingly. Then use this flag to control the flow of software. I'm sure I can do this work, but since I like to study and enjoy programming, I was wondering if there is a better approach or design template for disabling blocks of functionality that are not supported, as well as controlling the flow of execution.

Thank you in advance for your wisdom!

+3
3

Game Kit Apple dev. GameCenterManager, , .

+1

, , Facade Pattern. , , : , , , , - , , ,

, iOS/Object C, , .

+2

I usually test Game Center support with a simple C-style feature that extends Apple's recommended method. This adds a device test for the iPod Touch 1st Gen and 3G models, as the Apple code does not account for these devices.

#import <sys/utsname.h>

BOOL isGameCenterAvailable()
{
    // Check for presence of GKLocalPlayer API.
    Class gcClass = (NSClassFromString(@"GKLocalPlayer"));

    // The device must be running running iOS 4.1 or later.
    NSString *reqSysVer = @"4.1";
    NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
    BOOL osVersionSupported = ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending);

    // 1st Gen iPod and 3G don't support Game Center
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *theModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    if ([theModel isEqualToString:@"iPhone1,2"] ||
        [theModel isEqualToString:@"iPod1,1"])
    {
        return FALSE;
    }

    return (gcClass && osVersionSupported);
}

Use is as simple as

if (isGameCenterAvailable())
{
    // display game center UI
}
0
source

Source: https://habr.com/ru/post/1770966/


All Articles