`
shappy1978
  • 浏览: 680217 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

'uniqueIdentifier' is deprecated

 
阅读更多

//************************************************************************************officail suggestion

Special Considerations

Do not use the uniqueIdentifier property. To create a unique identifier specific to your app, you can call the CFUUIDCreate function to create a UUID, and write it to the defaults database using the NSUserDefaults class.

 

however this value won't be the same if a user uninstalls and re-installs the app.

 

uniqueDeviceIdentifier (MD5 of MAC+CFBundleIdentifier)

and uniqueGlobalDeviceIdentifier(MD5 of the MAC), these always returns the same values.

 

#import "UIDevice+IdentifierAddition.h"
#import "NSString+MD5Addition.h"

#include <sys/socket.h> // Per msqr
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>

@interface UIDevice(Private)

- (NSString *) macaddress;

@end

@implementation UIDevice (IdentifierAddition)

////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Private Methods

// Return the local MAC addy
// Courtesy of FreeBSD hackers email list
// Accidentally munged during previous update. Fixed thanks to erica sadun & mlamb.
- (NSString *) macaddress{
    
    int                 mib[6];
    size_t              len;
    char                *buf;
    unsigned char       *ptr;
    struct if_msghdr    *ifm;
    struct sockaddr_dl  *sdl;
    
    mib[0] = CTL_NET;
    mib[1] = AF_ROUTE;
    mib[2] = 0;
    mib[3] = AF_LINK;
    mib[4] = NET_RT_IFLIST;
    
    if ((mib[5] = if_nametoindex("en0")) == 0) {
        printf("Error: if_nametoindex error\n");
        return NULL;
    }
    
    if (sysctl(mib, 6, NULL, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 1\n");
        return NULL;
    }
    
    if ((buf = malloc(len)) == NULL) {
        printf("Could not allocate memory. error!\n");
        return NULL;
    }
    
    if (sysctl(mib, 6, buf, &len, NULL, 0) < 0) {
        printf("Error: sysctl, take 2");
        return NULL;
    }
    
    ifm = (struct if_msghdr *)buf;
    sdl = (struct sockaddr_dl *)(ifm + 1);
    ptr = (unsigned char *)LLADDR(sdl);
    NSString *outstring = [NSString stringWithFormat:@"%02X:%02X:%02X:%02X:%02X:%02X", 
                           *ptr, *(ptr+1), *(ptr+2), *(ptr+3), *(ptr+4), *(ptr+5)];
    free(buf);
    
    return outstring;
}

////////////////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark Public Methods

- (NSString *) uniqueDeviceIdentifier{
    NSString *macaddress = [[UIDevice currentDevice] macaddress];
    NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];  
    NSString *stringToHash = [NSString stringWithFormat:@"%@%@",macaddress,bundleIdentifier];
    NSString *uniqueIdentifier = [stringToHash stringFromMD5];  
    return uniqueIdentifier;
}

- (NSString *) uniqueGlobalDeviceIdentifier{
    NSString *macaddress = [[UIDevice currentDevice] macaddress];
    NSString *uniqueIdentifier = [macaddress stringFromMD5];    
    return uniqueIdentifier;
}

@end

 

#import "NSString+MD5Addition.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString(MD5Addition)

- (NSString *) stringFromMD5{
    
    if(self == nil || [self length] == 0)
        return nil;
    
    const char *value = [self UTF8String];
    
    unsigned char outputBuffer[CC_MD5_DIGEST_LENGTH];
    CC_MD5(value, strlen(value), outputBuffer);
    
    NSMutableString *outputString = [[NSMutableString alloc] initWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(NSInteger count = 0; count < CC_MD5_DIGEST_LENGTH; count++){
        [outputString appendFormat:@"%02x",outputBuffer[count]];
    }
    return [outputString autorelease];
}

@end
 
分享到:
评论

相关推荐

    创建 uniqueidentifier 类型的唯一值

    下面的示例使用 NEWID 对声明为 uniqueidentifier 数据类型的变量赋值。在测试该值前,将先打印 uniqueidentifier 数据类型变量的值。

    SqlServer中Int类型快速转uniqueidentifier

    SqlServer中Int类型快速转uniqueidentifier

    uniqueidentifier转换成varchar数据类型的sql语句

    代码如下: —涂聚文 Geovin Du DECLARE @myid uniqueidentifier SET @myid = NEWID() SELECT CONVERT(char(255), @myid) AS ‘char’; GO –涂聚文 Geovin Du declare @allstring char(255),@AreaUid ...

    解决sql server保存对象字符串转换成uniqueidentifier失败的问题

    客户要求,ID列的数据类型必须是uniqueidentifier,一开始实体类的ID设计成java.lang.String类型;映射文件中ID的增长方式是uuid.hex private java.lang.String id; public java.lang.String getId(){ return id; }...

    powerdesigner GUID uniqueidentifier测试数据生成补丁

    修正powerdesigner无法为SQL SERVER2005、2008自动生成GUID数据类型的测试数据问题,解压后直接覆盖相关文件。 建立test data profile,进行相关设置即可自动生成GUID测试数据。 具体设置可参照博文:...

    SQL Server导入MySQL.zip

    SQL Server导入MySQL,包括表结构及数据,uniqueidentifier 需要改变为字符类型

    SQL语句。。。。。。。。。

    ISNULL(, &lt;replacement_value&gt; ) --函数将表达式中的NULL 值用指定值替换 ISNUMERIC() --函数判断所给定的表达式是否为合理的数值 NEWID() --函数返回一个UNIQUEIDENTIFIER 类型的数值 NULLIF(, &lt;expression2&gt; ) ...

    sql 游标、存储过程

    isnull(c.name_ch, '')+isnull(','+d.name_ch, '') as tasteName_ch, isnull(c.name_en, '')+isnull(','+d.name_en, '') as tasteName_en, a.remark as remark from t_order_temp a left join t_dishes b on a....

    自己用的sql语句

    id uniqueidentifier primary key default newid(), name_ch nvarchar(20), naem_en nvarchar(60), d_code nvarchar(2) ) go insert into t_classify_method(id, name_ch, name_en, d_code) values ('2F71F378-...

    sql server中随机函数NewID()和Rand()

    在SQL Server中,随机函数有rand(),NewID(),其中rand是在0到1内随机取数,NewID则是生成随机的uniqueidentifier唯一标识符。 SELECT * FROM Northwind..Orders ORDER BY NEWID() –随机排序 SELECT TOP 10 * ...

    ImportSQL

    支持uniqueidentifier,image,nvarchar,int,datetime等类型数据导出。 使用方法: 1.设置数据库连接,启动程序时会弹出设置对话框,按左侧内容填写即可。 2.按条件导出:在tab的高级选项卡中输入where语句以后的...

    [详细完整版]公文数据结构.pdf

    DocumentID 公文序号 uniqueidentifier 2. CodeDepID 单位分类 序号 nvarchar(50) 3. CodeDep 单位分类 码 nvarchar(4) 4. CodeDepMeaning 单位分类 码意义 nvarchar(max) 5. CodeLevel 级别分类 码 nvarchar(2) 6....

    Sqlserver最新县及县以上行政区划代码

    国家统计局-发布时间:2016...[ID] [uniqueidentifier] NOT NULL, [CreateDate] [datetime] NOT NULL DEFAULT (getdate()), [TimeStamps] [timestamp] NULL, [Name] [nvarchar] (50) NULL, [Code] [nvarchar] (6) NULL)

    液位数据采集和接口文档1

    表名:LiquidMonitor液位计数据监测表序号列名数据类型长度小数位标识主键外键允许空默认值说明1IDuniqueidentifier40是否ID主键2A

    Laravel开发-laravel-mssql

    Laravel开发-laravel-mssql Laravel扩展,允许使用MS SQL特定的列类型,如“datetime2”、“real”和“uniqueidentifier”。

    如何使用KeyChain保存和获取UDID

    iOS2.0版本以后UIDevice提供一个获取设备唯一标识符的方法uniqueIdentifier,通过该方法我们可以获取设备的序列号,这个也是目前为止唯一可以确认唯一的标示符。好景不长,因为该唯一标识符与手机一一对应,苹果觉得...

    C#中序列化实现深拷贝,实现DataGridView初始化刷新的方法

    下面小编就为大家带来一篇C#中序列化实现深拷贝,实现DataGridView初始化刷新的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

    iOS使用网卡mac地址生成UUID

    苹果iOS 5.0以后不再支持uniqueIdentifier方法获取用户的UDID,替代的方法需要用户自己保存UUID。附件代码通过网卡mac地址生成UUID,取代原来方式,每次都会生成同样的并且唯一的UUID,不用保存,也不用担心iOS不同...

    ECommerceProject

    Id uniqueidentifier not null primary key, [Name] varchar(40) not null ) ; create table Customers( Id uniqueidentifier not null primary key, FirstName varchar(40) not null, LastName varchar(40) ...

Global site tag (gtag.js) - Google Analytics