获取设备id,imei
在此单独写成一个类方法进行调用方便。
.h文件
#import <Foundation/Foundation.h>
@interface DeviceInfoUtil : NSObject
/**
* 获取设备id
*
* @return return value NSString id
*/
+ (NSString *)getDeviceId;
@end
.m文件
#import "DeviceInfoUtil.h"
//#import "SSKeyChain.h"
#import <SSKeychain.h>
@implementation DeviceInfoUtil
+ (NSString *)getDeviceId
{
// NSString *retrieveuuid = [SSKeychain passwordForService:@"com.bolaihui.bolaihui"account:@"deviceId"];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *retrieveuuid = [userDefaults stringForKey:@"deviceId"];
if ( retrieveuuid == nil || [retrieveuuid isEqualToString:@""]){
CFUUIDRef uuid = CFUUIDCreate(NULL);
CFStringRef uuidStr = CFUUIDCreateString(NULL, uuid);
retrieveuuid = [NSString stringWithFormat:@"%@", uuidStr];
[userDefaults setValue:retrieveuuid forKey:@"deviceId"];
// [SSKeychain setPassword:retrieveuuid forService:@"com.bolaihui.bolaihui"account:@"deviceId"];
}
return retrieveuuid;
}
@end
设备imei
使用了AFNetwork库
//手机串号(区分设备)
[[BNetworkManager sharedInstance].requestSerializer setValue:[DeviceInfoUtil getDeviceId] forHTTPHeaderField:@"imei"];
调用:
param[kparam_imei] = [DeviceInfoUtil getDeviceId];