iPhone4S-会有UDID吗?

iPhone4S-会有UDID吗?,iphone,ios,udid,Iphone,Ios,Udid,我知道在iOS 5.0中UDID是不推荐的。在我发疯并更新所有具有[UIDevice currentDevice].uniqueIdentifier调用的应用程序之前,我想知道iPhone 4S是否会报告UDID 如果它有UDID,基本上可以省去我立即更新应用程序的麻烦。如果它没有UDID,并且在调用UDID后基本上终止了应用程序,那么我真的需要立即更新我的应用程序 提前感谢。-[UIDevice uniqueIdentifier]将继续在iOS 5中工作,但您应该转向另一种机制。它肯定仍然有效

我知道在iOS 5.0中UDID是不推荐的。在我发疯并更新所有具有[UIDevice currentDevice].uniqueIdentifier调用的应用程序之前,我想知道iPhone 4S是否会报告UDID

如果它有UDID,基本上可以省去我立即更新应用程序的麻烦。如果它没有UDID,并且在调用UDID后基本上终止了应用程序,那么我真的需要立即更新我的应用程序


提前感谢。

-[UIDevice uniqueIdentifier]
将继续在iOS 5中工作,但您应该转向另一种机制。

它肯定仍然有效-我们今天看到许多iPhone 4S用户登录我们的系统,他们的设备显示有效的UDID。(通过
uniqueIdentifier
获得)但苹果可能会在iOS 6中删除它,因此值得开始探索解决办法。

我建议将
uniqueIdentifier
改为(实际上是两个简单的类别)。它利用设备的MAC地址和应用程序包标识符在应用程序中生成一个唯一的ID,可以用作UDID替换

请记住,与UDID不同,每个应用程序的这个数字都会不同

您只需导入包含的
NSString
UIDevice
类别并调用:

#import "UIDevice+IdentifierAddition.h"
#import "NSString+MD5Addition.h"
NSString *iosFiveUDID = [[UIDevice currentDevice] uniqueDeviceIdentifier]
以获取生成的设备标识符

您可以在Github上找到它:


下面是代码(仅.m文件-检查github项目的标题):

UIDevice+IdentifierAddition.m

#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
#导入“UIDevice+IdentifierAddition.h”
#导入“NSString+MD5Addition.h”
#包括//每个msqr
#包括
#包括
#包括
@接口设备(专用)
-(NSString*)macaddress;
@结束
@实现设备(标识添加)
////////////////////////////////////////////////////////////////////////////////
#布拉格标记-
#pragma标记私有方法
//返回本地MAC地址
//由FreeBSD黑客电子邮件列表提供
//在上一次更新期间意外咀嚼。多亏了erica sadun和mlamb的修复。
-(NSString*)macaddress{
    
int-mib[6];
尺寸透镜;
char*buf;
无符号字符*ptr;
结构if_msghdr*ifm;
结构sockaddr_dl*sdl;
    
mib[0]=CTL_NET;
mib[1]=AF_路由;
mib[2]=0;
mib[3]=AF_链路;
mib[4]=净注册列表;
    
if((mib[5]=if_nametoindex(“en0”))==0){
printf(“错误:if_nametoindex Error\n”);
返回NULL;
    }
    
if(sysctl(mib,6,NULL,&len,NULL,0)<0){
printf(“错误:sysctl,取1\n”);
返回NULL;
    }
    
如果((buf=malloc(len))==NULL){
printf(“无法分配内存。错误!\n”);
返回NULL;
    }
    
if(sysctl(mib,6,buf,&len,NULL,0)<0){
printf(“错误:sysctl,取2”);
返回NULL;
    }
    
ifm=(结构if_msghdr*)buf;
sdl=(结构sockaddr_dl*)(ifm+1);
ptr=(无符号字符*)LLADDR(sdl);
NSString*outstring=[NSString stringWithFormat:@“%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X”,
*ptr,*(ptr+1),*(ptr+2),*(ptr+3),*(ptr+4),*(ptr+5)];
免费(buf);
    
回报突出;
}
////////////////////////////////////////////////////////////////////////////////
#布拉格标记-
#pragma标记公共方法
-(NSString*)唯一设备标识符{
NSString*macaddress=[[UIDevice currentDevice]macaddress];
NSString*bundleIdentifier=[[NSBundle mainBundle]bundleIdentifier]
NSString*stringToHash=[NSString stringWithFormat:@“%@%@”,macaddress,bundleIdentifier];
NSString*uniqueIdentifier=[stringToHash stringFromMD5]
返回唯一标识符;
}
-(NSString*)唯一的GlobalDeviceIdentifier{
NSString*macaddress=[[UIDevice currentDevice]macaddress];
NSString*uniqueIdentifier=[MacAddressStringFromMD5]
返回唯一标识符;
}
@结束
NSString+MD5Addition.m:

#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
#导入“NSString+MD5Addition.h”
#进口
@实现NSString(MD5Addition)
-(NSString*)stringFromMD5{
    
if(self==nil | |[self length]==0)
返回零;
    
常量字符*值=[self UTF8String];
    
无符号字符输出缓冲区[CC_MD5_DIGEST_LENGTH];
CC_MD5(值、strlen(值)、outputBuffer);
    
NSMutableString*outputString=[[NSMutableString alloc]initWithCapacity:CC_MD5_DIGEST_LENGTH*2];
对于(NSInteger count=0;count
尽管[[UIDevice currentDevice]uniqueDeviceIdentifier]仍然有效,但出于安全原因,苹果已经开始拒绝访问设备UDID的应用程序,因此最好找到UDID的另一种替代方案。 有关此链接的更多信息,请访问此链接:

Dave,我知道uniqueIdentifier将继续在当前设备上工作,但你真的知道它是否能在iPhone 4S上工作吗?证据?Dave,上次我检查时,开发人员不需要知道谁在UIKit团队工作。此外,上次我检查时,在没有实际解释的情况下,随机地听取人们对事情的看法是不好的做法。谢谢你的回答,但对于未来的回应,我建议你做一个更详细的解释,而不是让你的名声来说话。每一部iPhone都会有一个UDID,只是苹果不希望开发者使用它来识别他们用户的设备。那就是埃特伯勒,我想我真的不清楚不推荐的含义