기기별로 유일한 키를 사용하고 싶을때 아래 코드를 이용하면
기기별로 유일한 키를 얻어 사용할수있다.
앱을 삭제했다 다시깔아도 동일한 키가 추출된다.
PCL
{
public interface IDevice
{
string GetIdentifier();
}
}
Android
namespace Project.Droid
{
public class AndroidDevice : IDevice
{
public string GetIdentifier()
{
return Secure.GetString(Forms.Context.ContentResolver, Secure.AndroidId);
}
}
}
iOS
namespace Project.iOS
{
public class IOSDevice : IDevice
{
[DllImport("/System/Library/Frameworks/IOKit.framework/IOKit")]
private static extern uint IOServiceGetMatchingService(uint masterPort, IntPtr matching);
[DllImport("/System/Library/Frameworks/IOKit.framework/IOKit")]
private static extern IntPtr IOServiceMatching(string s);
[DllImport("/System/Library/Frameworks/IOKit.framework/IOKit")]
private static extern IntPtr IORegistryEntryCreateCFProperty(uint entry, IntPtr key, IntPtr allocator, uint options);
[DllImport("/System/Library/Frameworks/IOKit.framework/IOKit")]
private static extern int IOObjectRelease(uint o);
public string GetIdentifier()
{
string serial = string.Empty;
uint platformExpert = IOServiceGetMatchingService(0, IOServiceMatching("IOPlatformExpertDevice"));
if (platformExpert != 0)
{
NSString key = (NSString)"IOPlatformSerialNumber";
IntPtr serialNumber = IORegistryEntryCreateCFProperty(platformExpert, key.Handle, IntPtr.Zero, 0);
if (serialNumber != IntPtr.Zero)
{
serial = NSString.FromHandle(serialNumber);
}
IOObjectRelease(platformExpert);
}
return serial;
}
}
}
'C# > Xamarin Maui' 카테고리의 다른 글
authentication failure. Reason : {"authType" : "hsa2" } (0) | 2018.07.31 |
---|---|
NoCached WebView (0) | 2018.07.22 |
Could not find any available provisioning profiles for iOS. WorkingWithMaps.iOS (0) | 2018.07.17 |
incompatible hax module version 3 requires minimum version 4 (0) | 2018.07.17 |
에러 "java.exe"이(가) 종료되었습니다(코드:2) (0) | 2018.07.13 |