• iOS开发——设备信息小结(未完待续...)


      1.获取设备的信息

      UIDevice *device = [[UIDevice alloc] init];

        NSString *name = device.name;       //获取设备所有者的名称

        NSString *model = device.name;      //获取设备的类别

        NSString *type = device.localizedModel; //获取本地化版本

        NSString *systemName = device.systemName;   //获取当前运行的系统

        NSString *systemVersion = device.systemVersion;//获取当前系统的版本

        NSLog(@"name:%@ model:%@ type:%@ systemName:%@ systemVersion:%@ ",name,model,type,systemName,systemVersion);

      

      2.获取设备的唯一标示符

      NSString *identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

        NSLog(@"identifier:%@",identifier);

      3.创建一个uuid(一个随机的标示符)

      NSString *uuid = [self createUUID];

        NSLog(@"uuid:%@",uuid);

    - (NSString*)createUUID {

        NSString *id = [[NSUserDefaults standardUserDefaults] objectForKey:@"UUID"];    //获取标识为"UUID"的值

        if(id == nil)

        {

            if([[[UIDevice currentDevice] systemVersion] floatValue] > 6.0)

            {

                //ios 6.0 之后可以使用的api

                NSString *identifierNumber = [[NSUUID UUID] UUIDString];

                [[NSUserDefaults standardUserDefaults] setObject:identifierNumber forKey:@"UUID"];

                [[NSUserDefaults standardUserDefaults] synchronize];

            }

            else{

                //ios6.0之前使用的api

                CFUUIDRef uuid = CFUUIDCreate(NULL);

                CFStringRef uuidString = CFUUIDCreateString(NULL, uuid);

                NSString *identifierNumber = [NSString stringWithFormat:@"%@", uuidString];

                [[NSUserDefaults standardUserDefaults] setObject:identifierNumber forKey:@"UUID"];

                [[NSUserDefaults standardUserDefaults] synchronize];

                CFRelease(uuidString);

                CFRelease(uuid);

            }

            return [[NSUserDefaults standardUserDefaults] objectForKey:@"UUID"];

        }

        return id;

    }

      

      4.获取当前屏幕分辨率

      CGRect rect = [[UIScreen mainScreen] bounds];

        CGFloat scale = [[UIScreen mainScreen] scale];

        CGFloat width = rect.size.width * scale;

        CGFloat height = rect.size.height * scale;

        NSLog(@"%.f   height:%.f  scale:%.f",width,height,scale);

  • 相关阅读:
    JAVA 入门 28 多态综合案例 内部类
    面试~线程池三大方法、七个参数、四种拒绝策略、实际应用
    面试~ThreadLocal
    主从复制、哨兵模式
    面试java并发~(lock、volatile、cas)
    面试~jvm(JVM内存结构、类加载、双亲委派机制、对象分配,了解垃圾回收)
    安装nginx
    SpringBoot注入
    springboot 引入外部包的坑Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class
    mysql并发插入死锁
  • 原文地址:https://www.cnblogs.com/yyt-hehe-yyt/p/5439858.html
Copyright © 2020-2023  润新知