APP NAME: [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]

APP BUILD: [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]

APP VERSION: [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

设备版本号:[[[UIDevice currentDevice] systemVersion] integerValue]

+ (NSString * _Nonnull)uniqueIdentifier {//获取设备的uuid

NSString *UUID;

if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {

UUID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

} else {

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

UUID = [defaults stringForKey:BFUniqueIdentifierDefaultsKey];

if (!UUID) {

UUID = [NSString generateUUID];

[defaults setObject:UUID forKey:BFUniqueIdentifierDefaultsKey];

[defaults synchronize];

}

}

return UUID;

}

+ (NSString * _Nonnull)generateUUID {

CFUUIDRef theUUID = CFUUIDCreate(NULL);

CFStringRef string = CFUUIDCreateString(NULL, theUUID);

CFRelease(theUUID);

return (__bridge_transfer NSString *)string;

}

+ (NSNumber * _Nonnull)totalDiskSpace {//总共的硬盘大小

NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];

return [attributes objectForKey:NSFileSystemSize];

}

+ (NSNumber * _Nonnull)freeDiskSpace {//可用的硬盘大小

NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil];

return [attributes objectForKey:NSFileSystemFreeSize];

}

+ (NSUInteger)getSysInfo:(uint)typeSpecifier {

//RAM大小,其中typeSpecifier为HW_MEMSIZE

//cpu大小,其中typeSpecifier为HW_NCPU

//总内存大小,其中typeSpecifier为HW_PHYSMEM

//用户内存,其中typeSpecifier为HW_USERMEM

size_t size = sizeof(int);

int results;

int mib[2] = {CTL_HW, typeSpecifier};

sysctl(mib, 2, &results, &size, NULL, 0);

return (NSUInteger) results;

}

+ (NSString * _Nonnull)devicePlatform {//设备的类型(iphone,ipad,ipod,AppleTV)

size_t size;

sysctlbyname("hw.machine", NULL, &size, NULL, 0);

char *machine = malloc(size);

sysctlbyname("hw.machine", machine, &size, NULL, 0);

NSString *platform = [NSString stringWithUTF8String:machine];

free(machine);

return platform;

}

+ (BOOL)isRetina {//是Retina屏幕

if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 2.0 || [UIScreen mainScreen].scale == 3.0)) {

return YES;

} else {

return NO;

}

}

+ (BOOL)isRetinaHD {//是RetinaHD屏幕

if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] && ([UIScreen mainScreen].scale == 3.0)) {

return YES;

} else {

return NO;

}

}

+ (float)currentAppCPUUsage {//当前APPCPU资源

kern_return_t kr;

task_info_data_t tinfo;

mach_msg_type_number_t task_info_count;

task_info_count = TASK_INFO_MAX;

kr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)tinfo, &task_info_count);

if (kr != KERN_SUCCESS) {

return -1;

}

task_basic_info_t      basic_info;

thread_array_t         thread_list;

mach_msg_type_number_t thread_count;

thread_info_data_t     thinfo;

mach_msg_type_number_t thread_info_count;

thread_basic_info_t basic_info_th;

uint32_t stat_thread = 0;

basic_info = (task_basic_info_t)tinfo;

kr = task_threads(mach_task_self(), &thread_list, &thread_count);

if (kr != KERN_SUCCESS) {

return -1;

}

if (thread_count > 0) stat_thread += thread_count;

long tot_sec = 0;

long tot_usec = 0;

float tot_cpu = 0;

int j;

for (j = 0; j < thread_count; j++) {

thread_info_count = THREAD_INFO_MAX;

kr = thread_info(thread_list[j], THREAD_BASIC_INFO, (thread_info_t)thinfo, &thread_info_count);

if (kr != KERN_SUCCESS) {

return -1;

}

basic_info_th = (thread_basic_info_t)thinfo;

if (!(basic_info_th->flags & TH_FLAGS_IDLE)) {

tot_sec = tot_sec + basic_info_th->user_time.seconds + basic_info_th->system_time.seconds;

tot_usec = tot_usec + basic_info_th->system_time.microseconds + basic_info_th->system_time.microseconds;

tot_cpu = tot_cpu + basic_info_th->cpu_usage / (float)TH_USAGE_SCALE * 100.0;

}

}

kr = vm_deallocate(mach_task_self(), (vm_offset_t)thread_list, thread_count * sizeof(thread_t));

assert(kr == KERN_SUCCESS);

return tot_cpu;

}

+ (BOOL)isJailBreak

{//是否越狱  

BOOL cydia = NO;

BOOL binBash = NO;

NSString *filePath = @"/Applications/Cydia.app";

if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])

{

cydia = YES;

}

FILE * f = fopen("/bin/bash", "r");

if (f != NULL)

{

binBash = YES;

}

fclose(f);

if (cydia || binBash) {

return YES;

} else {

return NO;

}

}

//获取设备所连wifi信号强度

- (NSString*)fetchSSIDInfo {

NSString *ssid = nil;

NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();

for (NSString *ifnam in ifs) {

NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);

if (info[@"SSID"]) {

ssid = info[@"SSID"];

}

}

return ssid;

}

//获得所连Wi-Fi的Mac地址

- (NSString*)fetchBSSIDInfo {

NSString *bssid = nil;

NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces();

for (NSString *ifnam in ifs) {

NSDictionary *info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);

if (info[@"BSSID"]) {

bssid = info[@"BSSID"];

}

}

//去除冒号

return [bssid stringByReplacingOccurrencesOfString:@":" withString:@""];

}

//获取广播地址

-(NSString *)getIpAddressInfo{

struct ifaddrs *interfaces = NULL;

struct ifaddrs *temp_addr = NULL;

NSString *address;

getifaddrs(&interfaces);

temp_addr = interfaces;

while (temp_addr!=NULL) {

NSString *ifa_name = [NSString stringWithUTF8String:temp_addr->ifa_name];

if ([ifa_name isEqualToString:@"en0"]&&temp_addr->ifa_addr->sa_family == AF_INET) {

unsigned int IP = ((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr.s_addr;

unsigned int mask = ((struct sockaddr_in *)temp_addr->ifa_netmask)->sin_addr.s_addr;

myHost = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)];

unsigned int temp = (IP&mask)|(~mask);//计算广播地址

struct in_addr inaddr;

inaddr.s_addr = temp;

address = [NSString stringWithUTF8String:inet_ntoa(inaddr)];

return address;

}

temp_addr = temp_addr->ifa_next;

}

return nil;

}

获取APP和设备相关信息的更多相关文章

  1. AD命令获取计算机、用户相关信息

    1. 获取AD用户相关信息(用户名.创建日期.最后修改密码日期.最后登录日期) Get AD users, Name/Created Date/Last change passwd Date/Last ...

  2. stat(),lstat(),fstat() 获取文件/目录的相关信息

    stat 的使用 Linux有个命令,ls -l,效果如下: 这个命令能显示文件的类型.操作权限.硬链接数量.属主.所属组.大小.修改时间.文件名.它是怎么获得这些信息的呢,请看下面的讲解. stat ...

  3. 关于Android的Build类——获取Android手机设备各种信息

    经常遇到要获取Android手机设备的相关信息,来进行业务的开发,比如经常会遇到要获取CPU的类型来进行so库的动态的下载.而这些都是在Android的Build类里面.相关信息如下: private ...

  4. 编程实战——电影管理器之利用MediaInfo获取高清视频文件的相关信息

    随着高速(20M)宽带.HTPC.大容量硬盘(3T)的普及,下载高清片并利用大屏幕观看也成为普通的事情. 随着下载影片的增多,管理就有了问题,有时在茫茫文件夹下找寻一个影片也是一件费时费力的事. 于是 ...

  5. [Android]获取设备相关信息

    public static int screenWidth(Activity activity) { DisplayMetrics dm = new DisplayMetrics(); activit ...

  6. android 获取 imei号码 及相关信息

    android 获取 imei号码 参考:http://www.cnblogs.com/luxiaofeng54/archive/2011/03/01/1968063.html 核心代码: Imei ...

  7. iOS获取运营商的相关信息

    1.导入:CoreTelephony.framework 2.添加头文件 #import <CoreTelephony/CTTelephonyNetworkInfo.h> #import ...

  8. js获取浏览器和设备相关width(屏幕的宽度)

    首先呢,我们将iPhone手机的相关数据表示如下 我们要理解很多东西,比如逻辑分辨率.物理分辨率.缩放因子.ppi等,这里先不讨论. 首先呢,我们先介绍下各个屏幕宽度: 网页可见区域宽: docume ...

  9. 【Android M】获取屏幕锁定的相关信息:“无”,“滑动”,“PIN码”,"图案","密码"

    ENV: Android M 6.0.1 import android.os.UserHandle;         import com.android.internal.widget.LockPa ...

随机推荐

  1. 用OpenGL实现动态的立体时钟

    (在学期末做的图形学课程设计,特将学习心得整理如下) 一.设计思路 1,设计一个平面的时钟: 按照 钟面——>中心点——>刻度——>时针——>分针——>秒针 的顺序绘制. ...

  2. 小程序返回顶部top滚动

    wxjs const app = getApp(); Page({ data:{ // top标签显示(默认不显示) backTopValue:false }, // 监听滚动条坐标 onPageSc ...

  3. 分辨率,PPi,DPI,DPR,物理像素,逻辑像素

    屏幕尺寸:指的是屏幕对角线的长度 分辨率:是指宽度上和高度上最多能显示的物理像素点个数 点距:像素与像素之间的距离,点距和屏幕尺寸决定了分辨率大小 PPI:屏幕像素密度,即每英寸(1英寸=2.54厘米 ...

  4. 慢慢看Spring源码

    1. 要想在java技术上提升一下,不看一下java源码是不行的,jdk源码,框架源码等.但是源码那么多,专门去看源码肯定很枯燥,所以就得一点一点看,坚持下去.有一点心得就记一点,如org.sprin ...

  5. MySQL 之 表操作

    一 什么是表 表(TABLE) 是一种结构化的文件,可用来存储某种特定类型的数据.表中的一条记录有对应的标题,标题 称之为 表的字段. 二 创建表 1 2 3 4 5 CREATE TABLE 表名( ...

  6. A - Fire Net

    Suppose that we have a square city with straight streets. A map of a city is a square board with n r ...

  7. F - Fibonacci again and again

    任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的: F(1)=1; F(2)=2; F(n)=F(n-1)+F(n-2)(n>=3); 所以,1, ...

  8. 设计模式学习--Prototype

    What Prototype:用原型实例指定创建对象的种类,并且通过拷贝这些原型创建新的对象. Why Prototype适用于在一个类的实例有几种不同的状态组合的一种时,建立相应的数目的原型并克隆她 ...

  9. centos下nginx的启动

    今天下载了个nginx,编译安装之后,无法启动,以前的启动方法无法实现(services nginx start), 在网上找了半天,才找到一个方法,与大家分享: 命令如下: 启动:/usr/loca ...

  10. JavaScript----特效代码

    1.不同时间段显示不同问候语 <Script Language="JavaScript"> <!-- var text=""; day = n ...