16

識別子を取得するために次のコードを使用しています

        deviceName = [[UIDevice currentDevice]uniqueIdentifier];

しかし、警告 uniqueIdentifier is deprecated in ios5.

ios5で識別子の値を取得するにはどうすればよいですか?

4

4 に答える 4

18

次のコードを使用できます

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」識別子を報告するバグがあります -詳細情報

于 2012-09-26T14:23:18.887 に答える
1

UUID を取得できなくなりました。そうすることは禁じられており、アプリは Apple によって拒否されます。

于 2012-09-26T10:29:59.420 に答える
0

J.Costaによって実証された方法は、iOS 6 に適しています。

ただし、ユーザーが電話をアップグレードしたときにアプリ内で同じ識別子を保持したい場合、または複数のアプリ内で (同じバンドル シード ID を共有していない限り)、これを使用します: https://github.com/blackpixel/BPXLUUIDHandler

非常に便利!

于 2012-09-26T14:39:09.410 に答える