我给你2个选择。
首先,简单的方法。一段时间以来,苹果禁止访问设备 ID。但是,它们会给您一个设备令牌。
要获得此唯一令牌,用户必须注册远程通知。
在应用程序启动时,调用以下函数:
[[UIApplication sharedApplication] registerForRemoteNotificationTypes (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
然后将调用此回调:
- (void)application:didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken.
将令牌发送到您的服务器,您就完成了。这种方法的问题是显而易见的。您的用户必须注册远程通知。
另一种方法是使用 wi-fi 板的 MAC 地址。
去做这个:
IP地址.h
IP地址.c
将此文件导入您的项目。然后使用这个函数:
InitAddresses();
GetHWAddresses();
for (int i=0; i<MAXADDRS; ++i)
{
//There is a way you can obtain more info about the hw_addrs, but in general, it's the first.
NSLog(@"MAC: %s", hw_addrs[i]);
}
FreeAddresses();
使用上面的mac地址创建一个哈希,你就完成了。
希望能帮助到你。