getting error on Plugin.DeviceInfo.CrossDeviceInfo.Current.Id

Bhuwan 956 Reputation points
2024-02-08T14:49:11.5433333+00:00

hi i am migrating xamarin to maui but getting below error for iOS and android is working fine Plugin.DeviceInfo.CrossDeviceInfo.Current.Id not working on iOS and getting this error - This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation. any other way in MAUI to get harderware id both Android and iOS

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2024-02-09T02:44:54.1566667+00:00

    Hello,

    The migration of third-party Nuget packages is not currently supported by Q&A.

    For the available APIs for obtaining device information in MAUI, you could refer to the Device information.

    For ID acquisition, you could use the following methods instead.

    // For Android
        public static class AndroidIDHelper
        {
            public static string GetID()
            {
                var context = Application.Context;
                return Secure.GetString(context.ContentResolver, Secure.AndroidId);
            }
        }
    // For iOS
        public static class IOSIDhelper
        {
            public static string GetID()
            {
                return UIDevice.CurrentDevice.IdentifierForVendor.AsString();
            }
        }
    
    // invoke
    #if ANDROID
    
                Console.WriteLine(AndroidIDHelper.GetID());
    #endif
    #if IOS
                Console.WriteLine(IOSIDhelper.GetID());
    #endif
    

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.