0

異なるプラットフォームを比較するにはどうすればよいですか?

例: 現在のデバイスが iPhone 4S よりも古いかどうかを知りたい。

4

2 に答える 2

3

これらのメソッドをいくつかのクラス (例: YourClass) に追加します。

+(NSString*)deviceVersion{
    // get hardware device version string
    struct utsname systemInfo;
    uname(&systemInfo);
    return [NSString stringWithCString:systemInfo.machine
                              encoding:NSUTF8StringEncoding];
    /*      possible values:
     @"i386" (or similar)     on the simulator //
     @"iPod1,1"   on iPod Touch
     @"iPod2,1"   on iPod Touch Second Generation
     @"iPod3,1"   on iPod Touch Third Generation
     @"iPod4,1"   on iPod Touch Fourth Generation
     @"iPhone1,1" on iPhone
     @"iPhone1,2" on iPhone 3G
     @"iPhone2,1" on iPhone 3GS
     @"iPad1,1"   on iPad
     @"iPad2,1"   on iPad 2
     @"iPad3,1"   on iPad 3 (aka new iPad)
     @"iPhone3,1" on iPhone 4
     @"iPhone4,1" on iPhone 4S
     @"iPhone5,1" on iPhone 5
     @"iPhone5,2" on iPhone 5
     ...future version...?       */
}

+(NSNumber *)getVersionForDevice:(NSString*)deviceToCheck{
    NSNumber* versionNumber = nil;
    if (deviceToCheck && ![deviceToCheck isEqualToString:@""]) {
        NSString* deviceMachine = [Utils deviceVersion];
        NSString* deviceVersion = nil;
        if ([deviceMachine hasPrefix:deviceToCheck]) {
            deviceVersion = [deviceMachine stringByReplacingOccurrencesOfString:deviceToCheck withString:@""];
            deviceVersion = [deviceVersion stringByReplacingOccurrencesOfString:@"," withString:@"."];
            float floatVersion = [deviceVersion floatValue];
            versionNumber = [NSNumber numberWithFloat:floatVersion];
        }
    }
    return versionNumber;
}


+(BOOL)isSimulator{
    NSString* deviceMachine = [Utils deviceVersion];
    //    NSLog(@"Utils deviceMachine: %@", deviceMachine);
    if (![deviceMachine hasPrefix:@"iPhone"] && ![deviceMachine hasPrefix:@"iPod"] && ![deviceMachine hasPrefix:@"iPad"]) {
        return 1;
    }
    return 0;
}

次に、iPhone でバージョンをテストしたい場合:

float iPhoneVersion = [[YourClass getVersionForDevice:@"iPhone"] floatValue];

iPad... iPod... に対しても同様の呼び出しを行います。

于 2013-01-18T13:11:40.957 に答える
-1

比較を行う必要がある場合は、使用できます

次に、同じタイプのプラットフォームを簡単に比較できます

UIDeviceComparisonResult result = [[UIDevice currentDevice] compareCurrentPlatformWithOtherPlatform:@"iPhone4,1"];
BOOL isOlderThanIPhone4S = result == UIDeviceComparisonResultOtherNewer;
return isOlderThanIPhone4S;

プラットフォームのすべての名前は、UIDevice-Hardware.m にあります。

于 2013-01-18T12:14:23.283 に答える