获取手机唯一标识码

来源:互联网 发布:怎么查询计算机端口号 编辑:程序博客网 时间:2024/05/02 04:30

现在活得手机唯一标示码,不太容易,我也是搞了好半天才弄到方法,在此分享给大家,顺便总结一下.

1.首先去github下载 sskeychain-master包,我们需要里面的SSKeychain.h和SSKeychain.m文件即可

2.然后建一个继承NSobject得类

3.在里面写上:

#import <Foundation/Foundation.h>


@interface UUID : NSObject


+ (NSString*) gen_uuid;


@end

.m里

#import "UUID.h"


@implementation UUID


+(NSString*) gen_uuid


{

    

    CFUUIDRef uuid_ref=CFUUIDCreate(nil);

    

    CFStringRef uuid_string_ref =CFUUIDCreateString(nil, uuid_ref);

    

    CFRelease(uuid_ref);

    

    NSString *uuid=[NSStringstringWithString:(__bridgeNSString * _Nonnull)(uuid_string_ref)];

    

    CFRelease(uuid_string_ref);

    

    return uuid;

    

}


@end


然后就可以调用了

#import "ViewController.h"


#import "SSKeychain.h"


#import "UUID.h"


#define kService [NSBundle mainBundle].bundleIdentifier


#define kAccount @"K626P85663.com.tzd.mofi2"//这个码是我们自己定的


@interface ViewController ()


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    //获取UUID,保存在钥匙串中(蓝色部分为标识,最好为app唯一标识,通过此标识查找保存的钥匙串)

    


    

    //获取设备唯一码

    

    if(![SSKeychainpasswordForService:kServiceaccount:kAccount])

        

    {

        

        NSString *uuid = [UUIDgen_uuid];

        

        [SSKeychainsetPassword:uuid forService:kServiceaccount:kAccount];

        

    }

    

    NSString *devicenumber = [SSKeychainpasswordForService:kServiceaccount:kAccount];

    

    这个字符串就是我们需要的了! 

}

测试过 得到的标识码基本不会变

0 0
原创粉丝点击