Use of Xamarin.mobile libraries, but they don't work

FraR1097FraR1097 Member ✭✭

Good Morning,
I am studying and am at the first of my multi-platform app on Xamarin.forms and it asks me to use the Xamarin.mobile libraries, but in the Android project after installing them as if they didn't recognize them and in the IOS project from incompatibility, how can I solve?

To specify I'm using Visual Studio for Mac and I download the libraries through the Nuget Manager

Posts

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
  • FraR1097FraR1097 Member ✭✭
    edited May 10

    Yes, I'm talking about that, and the book I'm following makes it easy to install and see that everything goes, but it's not @AlessandroCaliaro

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I thins it's deprecated. What should you do with that package?

  • FraR1097FraR1097 Member ✭✭
    edited May 10

    @AlessandroCaliaro
    I have to enable access to contacts and geolocation

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    For Geolocation you can Try Xamarin.Essentials.

    For contact, it seems there is nothing in Xamarin.Essentials https://github.com/xamarin/Essentials/issues/299

    you can take a look to this: https://www.c-sharpcorner.com/article/xamarin-forms-mvvm-how-to-fetch-mobile-contacts/

  • FraR1097FraR1097 Member ✭✭

    @AlessandroCaliaro thanks, the book I'm using gives me the projects already done, but I know it's an old version since it still speaks of xamarin studio and not of Visual Studio for Mac

  • FraR1097FraR1097 Member ✭✭
    edited May 10

    @AlessandroCaliaro This is the code I must use for android:

    public class ContactsService : IFriendService
    {
        public async Task<User[]> GetFriends(string userName)
        {
            var book = new Xamarin.Contacts.AddressBook(Application.Context);
            await book.RequestPermission();
    
            var users = new List<User>();
            foreach (var contact in book)
            {
                users.Add(new User
                {
                    Name = contact.DisplayName,
                });
            }
            return users.ToArray();
        }
    }
    
  • FraR1097FraR1097 Member ✭✭
    using System;
    using System.Threading.Tasks;
    
    
    namespace XamSnap.Droid
    {
        public class LocationService : ILocationService
        {
            private const int Timeout = 3000;
            private Geolocator _geolocator;
    
            public async Task<Location> GetCurrentLocation()
            {
                try
                {
                    //NOTE: wait until here to create Gelocator, so that the iOS prompt appears on GPS request
                    if (_geolocator == null)
                        _geolocator = new Geolocator(Application.Context);
    
                    var location = await _geolocator.GetPositionAsync(Timeout);
    
                    Console.WriteLine("GPS location: {0},{1}", location.Latitude, location.Longitude);
    
                    return new Location
                    {
                        Latitude = location.Latitude,
                        Longitude = location.Longitude,
                    };
                }
                catch (Exception exc)
                {
                    Console.WriteLine("Error finding GPS location: " + exc);
    
                    //If anything goes wrong, just return null as if it was not found
                    return null;
                }
            }
        }
    }
    
  • FraR1097FraR1097 Member ✭✭
    edited May 10

    .

Sign In or Register to comment.