主要研究UIDevice 类。
-
//获取设备id号
UIDevice *device = [UIDevice currentDevice];//创建设备对象
NSString *deviceUID = [[NSString alloc] initWithString:[device uniqueIdentifier]];
NSLog(@"%@",deviceUID); // 输出设备id - NSString *version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];//获取软件版本号
- NSString *systemVersion = [[UIDevice currentDevice] systemVersion];//系统版本
- NSString *systemModel = [[UIDevice currentDevice] model];//是iphone 还是 ipad
- NSDictionary *dic = [[NSBundle mainBundle] infoDictionary];//获取info-plist
- NSString *appName = [dic objectForKey:@"CFBundleIdentifier"];//获取Bundle identifier
- NSString *appVersion = [dic valueForKey:@"CFBundleVersion"];//获取Bundle Version
- NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:
- deviceID, @"deviceID",
- systemVersion, @"systemVersion",
- systemModel, @"systemModel",
- appName, @"appName",
- appVersion, @"appVersion",nil];
获取UUID并存储
UDID被弃用,使用UUID来作为设备的唯一标识。获取到UUID后,如果用NSUserDefaults存储,当程序被卸载后重装时,再获得的UUID和之前就不同了。使用keychain存储可以保证程序卸载重装时,UUID不变。但当刷机或者升级系统后,UUID还是会改变的。但这仍是目前为止最佳的解决办法了,如果有更好的解决办法,欢迎留言。
#import尖括号(Foundation/Foundation.h)
@interface UUID : NSObject
+(NSString *)getUUID;
@end
#import "UUID.h"
#import
#import"KeychainItemWrapper.h"
@implementation UUID
+(NSString *)getUUID
{
}
@end