識別子を取得するために次のコードを使用しています
deviceName = [[UIDevice currentDevice]uniqueIdentifier];
しかし、警告 uniqueIdentifier is deprecated in ios5.
ios5で識別子の値を取得するにはどうすればよいですか?
次のコードを使用できます
if ([[UIDevice currentDevice] respondsToSelector:@selector(identifierForVendor)]) {
// This will run if it is iOS6 or higher
return [[[UIDevice currentDevice] identifierForVendor] UUIDString];
} else {
// This will run before iOS6 and you can use openUDID or other
// method to generate an identifier
}
このようにして、以前の最小要件を維持できます。
この識別子は、1 つのベンダーのすべてのアプリに対して一意です。デバイスの一意の識別子が必要な場合は、次を使用する必要があります。
if (!NSClassFromString(@"ASIdentifierManager")) {
// This will run before iOS6 and you can use openUDID, per example...
return [OpenUDID value];
}
return [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString];
警告: iOS6 には、デバイスが「空気によって」更新された場合に「null」識別子を報告するバグがあります -詳細情報
UUID を取得できなくなりました。そうすることは禁じられており、アプリは Apple によって拒否されます。
J.Costaによって実証された方法は、iOS 6 に適しています。
ただし、ユーザーが電話をアップグレードしたときにアプリ内で同じ識別子を保持したい場合、または複数のアプリ内で (同じバンドル シード ID を共有していない限り)、これを使用します: https://github.com/blackpixel/BPXLUUIDHandler
非常に便利!