美文网首页
机型判断

机型判断

作者: iOS扫地僧 | 来源:发表于2017-11-21 11:15 被阅读0次

    方法

    - (BOOL)isSuitableMachine:(int)targetPlatNum {
        int mib[2] = {CTL_HW, HW_MACHINE};
        size_t len = 0;
        char *machine;
    
        sysctl(mib, 2, NULL, &len, NULL, 0);
    
        machine = (char *) malloc(len);
        sysctl(mib, 2, machine, &len, NULL, 0);
    
        NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
        NSLog(@"hhhhhhhhhhhhhh======%@",platform);
        free(machine);
        if ([platform length] > 6) {
            NSString *platNum = [NSString stringWithFormat:@"%C", [platform characterAtIndex:6]];
            if([platform containsString:@"iPhone"]){
                NSArray *array = [platform componentsSeparatedByString:@","];
                NSString *str = array[0];
                platNum = [str substringWithRange:NSMakeRange(6, str.length-6)];
            }
            return ([platNum intValue] >= targetPlatNum);
        } else {
            return NO;
        }
    }
    

    调用

    判断是否是6以上手机

    [self isSuitableMachine:7]
    

    判断是否是5以上手机

    [self isSuitableMachine:5]
    

    相关文章

      网友评论

          本文标题:机型判断

          本文链接:https://www.haomeiwen.com/subject/gjiivxtx.html